UI细节属性控件类iOS开发记录

UIButton(左边图片右边文字)

2015-03-02  本文已影响19881人  guaker
normal
highlighted
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 100, 50);
button.backgroundColor = [UIColor clearColor];
//设置button正常状态下的图片
[button setImage:[UIImage imageNamed:@"_star_normal.png"] forState:UIControlStateNormal];
//设置button高亮状态下的图片
[button setImage:[UIImage imageNamed:@"_star_highlighted.png"] forState:UIControlStateHighlighted];
//设置button正常状态下的背景图
[button setBackgroundImage:[UIImage imageNamed:@"_normal.png"] forState:UIControlStateNormal];
//设置button高亮状态下的背景图
[button setBackgroundImage:[UIImage imageNamed:@"_highlighted.png"] forState:UIControlStateHighlighted];
//button图片的偏移量,距上左下右分别(10, 10, 10, 60)像素点
button.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 60);
[button setTitle:@"南瓜瓜" forState:UIControlStateNormal];
//button标题的偏移量,这个偏移量是相对于图片的
button.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
//设置button正常状态下的标题颜色
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//设置button高亮状态下的标题颜色
[button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
button.titleLabel.font = [UIFont systemFontOfSize:14];
[self.view addSubview:button];
上一篇下一篇

猜你喜欢

热点阅读