1.工具栏UIToolBar管理了一组UIBarButtonItem,
UIBarButtonItem不能随意摆放在屏幕上,它不是继承自UIView。它由导航栏,标签栏或工具栏管理。
栏按钮条目UIBarButtonItem存储工具栏和导航栏的按钮的属性,它本身不是按钮。
UIBarButtonItem Class Reference
2. UIBarButtonItem有两种类型:按钮元素,空白元素。
UIBarButtonSystemItem枚举表示着不同的系统预设UIBarButtonItem;
UIBarButtonSystemItemFixedSpace类型表示一段空白,需要设置它的宽度值;可以使用它替换需要隐藏的项,以保持位置不变;
在UIToolBar开头和末尾添加UIBarButtonSystemItemFlexibleSpace会使其它项有不同有水平对齐方式;
3.透明背景UIToolBar
@interface TransportationToolbar : UIToolbar
@end
@implementation TransportationToolbar
- (void)drawRect:(CGRect)rect
{
// do nothing
}
- (id)initWithFrame:(CGRect)aRect
{
if ((self = [super initWithFrame:aRect]))
{
//self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.clearsContextBeforeDrawing = YES;
}
return self;
}
@end
然后在UIToolBar中添加各种UIBarButtonItem,以把UIBarButtonItem应用到各种地方。
注意UIToolBar虽然透明了,但需要把它的大小设置以容纳所有UIBarButtonItem,UIBarButtonItem才能有效点击。
4.UIBarButtonItem
设置背景色 setTintColor
设置文本颜色
NSDictionary* textAttributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorInSkinWithKey:@"subTextColor"], UITextAttributeTextColor,
//[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor,
//[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
//[UIFont fontWithName:@"AmericanTypewriter" size:0.0], UITextAttributeFont,
nil];
[rightButtonItem setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
UIBarItem::- (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state 可以设置多个文本参数。
/* Keys for text attributes dictionaries.
*/
// Key to the font in the text attributes dictionary. A UIFont instance is expected. Use a font with size 0.0 to get the default font size for the situation.
UIKIT_EXTERN NSString *const UITextAttributeFont NS_AVAILABLE_IOS(5_0);
// Key to the text color in the text attributes dictionary. A UIColor instance is expected.
UIKIT_EXTERN NSString *const UITextAttributeTextColor NS_AVAILABLE_IOS(5_0);
// Key to the text shadow color in the text attributes dictionary. A UIColor instance is expected.
UIKIT_EXTERN NSString *const UITextAttributeTextShadowColor NS_AVAILABLE_IOS(5_0);
// Key to the offset used for the text shadow in the text attributes dictionary. An NSValue instance wrapping a UIOffset struct is expected.
UIKIT_EXTERN NSString *const UITextAttributeTextShadowOffset NS_AVAILABLE_IOS(5_0);
5.