UIButton(左边图片右边文字)
2016-06-16 17:01
549 查看
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];
相关文章推荐
- iOS开发之路--微博“更多”页面
- iOS开发之路--微博骨架搭建
- iOS开发使用JSON解析网络数据
- IOS开发代码分享之获取启动画面图片的string
- iOS开发实现音频播放功能
- iOS开发之视图切换
- iOS开发使用XML解析网络数据
- IOS开发实现录音功能
- iOS开发之UIScrollView详解
- IOS开发之路--C语言数组和字符串
- iOS开发之触摸事件
- IOS开发代码分享之用nstimer实现倒计时功能
- 详解iOS中UIButton的三大UIEdgeInsets属性用法
- iOS开发使用GDataXML框架解析网络数据
- iOS开发之UITableView详解
- iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片上下垂直居中对齐
- IOS开发代码分享之设置UISearchBar的背景颜色
- Swift之贪婪的UIButton
- ios推送证书
- iOS和tvOS游戏按需加载资源简介