UIToolBar,UIBarButtonItem

1.工具栏UIToolBar管理了一组UIBarButtonItem,  

   UIBarButtonItem不能随意摆放在屏幕上,它不是继承自UIView。它由导航栏,标签栏或工具栏管理。

   栏按钮条目UIBarButtonItem存储工具栏和导航栏的按钮的属性,它本身不是按钮。


    UIBarButtonItem Class Reference

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html


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.







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值