在网上闲逛,无意中得知如此神奇的一个秘密。UIButton 的type在官方文档是这样定义的:
typedef enum { UIButtonTypeCustom = 0, UIButtonTypeRoundedRect,//圆角矩形按钮 UIButtonTypeDetailDisclosure,//详情显示按钮 UIButtonTypeInfoLight,//高亮背景显示信息按钮 UIButtonTypeInfoDark,//暗淡背景显示信息按钮 UIButtonTypeContactAdd,//添加联系人按钮 } UIButtonType;那么 ,你以为UIButton就只有官方文档所提供的那几种风格么?错啦!
试试下面的代码吧:
UIButton *myButton=[UIButton buttonWithType:101]; myButton.frame=CGRectMake(0, 0, myButton.frame.size.width, myButton.frame.size.width); [myButton setTitle:@"水果" forState:UIControlStateNormal]; [self.view addSubview:myButton];同样的,UIBarButtonItem也不只官方文档所提供的那24种风格,当然你可以自定义View,那样的就随意多了去了。我这里说的是水果公司没有公开的几种风格。试试下面的代码:
NSMutableArray *myitems = [NSMutableArray array]; UIBarButtonItem *item = nil; for (int i = 100; i <= 109; i++) { item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:i target:nil action:nil]; item.style = UIBarButtonItemStyleBordered; [myitems addObject:item]; } item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:110 target:nil action:nil]; item.style = UIBarButtonItemStylePlain; [myitems addObject:item]; toolbar.items = myitems;上面的运行结果为:
UIButton 101 风格
UIBarButtonItem100~110风格
经测试,在UIButton中可以使用100、101、102、103四种非公开的风格,其中103以上都是一样的。也是说你指定103和指定110没有差别。
而UIBarButtonItem的非公开风格,一共9种,其定义为:
100 UIButtonBarLocate.png 101 UIButtonBarArrowLeft.png 102 UIButtonBarArrowRight.png 103 UIButtonBarArrowUp.png 104 UIButtonBarArrowDown.png 105 UIButtonBarArrowLeft.png 106 UIButtonBarArrowRight.png 107 UIButtonBarPreviousSlide.png 108 UIButtonBarNextSlide.png可以看出, (101,102与105,106相同)。至于水果为何会留这么一个“洞穴”,我也就不知道了,暂时还悟不透。
注:以上内容参考了易飞扬大哥的博客,易飞扬大哥是很牛气的程序员,他的博客地址是:http://www.yifeiyang.net。据我的观察,在程序员的分级中【IT领袖:年入过亿(例如任正非、马化腾、李彦宏、丁磊、马云等)IT大哥:年入千万(级别次于以上几位大佬的公司老板)IT精英:年入百万(各IT公司副总裁级别人物,包括COO、CTO等,大多为职业经理人)IT人才:年入50万(各IT公司总监级别人物,有房有车)IT工程师:年入20万(高级经理级别,有房贷,生活压力大)IT民工:年入10万(经理级别,基本无房,生活压力大)码农:年入6万到10万(工作三四年,租房,继续混日子)码奴:年入3万到6万(工作一两年,租房,混日子)码畜:年入低于3万(刚毕业的,租房,傻乐)】飞扬哥应该是人才以上的。