iPhone UIButton 图标与文字间距设置
2014-04-19 16:29
429 查看
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 150, 50)];
[button setTitle:@"HHH" forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"narrowend.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"panelicon.png"] forState:UIControlStateNormal];
默认情况下,图片及按钮文字如下:
加入如下代码后
[button setImageEdgeInsets:UIEdgeInsetsMake(0.0, -20, 0.0, 0.0)];
[button setImageEdgeInsets:UIEdgeInsetsMake(<#CGFloat top#向上偏移量>, <#CGFloat left#向左偏移量>, <#CGFloat bottom#向下偏移量>, <#CGFloat right#向右上偏移量>)];
同时还可以设置文字的偏移量:
[button setTitleEdgeInsets:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];
[button setTitle:@"HHH" forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"narrowend.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"panelicon.png"] forState:UIControlStateNormal];
默认情况下,图片及按钮文字如下:
加入如下代码后
[button setImageEdgeInsets:UIEdgeInsetsMake(0.0, -20, 0.0, 0.0)];
[button setImageEdgeInsets:UIEdgeInsetsMake(<#CGFloat top#向上偏移量>, <#CGFloat left#向左偏移量>, <#CGFloat bottom#向下偏移量>, <#CGFloat right#向右上偏移量>)];
同时还可以设置文字的偏移量:
[button setTitleEdgeInsets:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];
相关文章推荐
- iOS7新特性之TextKit(三)NSTextStorage,NSLayoutManager,NSTextContainer和UITextView
- POJ 3094 - Quicksum
- UITextView
- NGUI官网示例7-- ScrollView讲解
- iOS开发- UICollectionView详解+实例
- QUI操作超时弹出登录窗口登录的处理方式
- 截图UIView的某个CGRect,返回图片
- UILabel居上对齐居下对齐类别扩展
- UIVIEW圆角和边框设置
- The user operation is waiting for "building workspace" to complete”
- mysql中key 、primary key 、unique key 与index区别
- 【UIKit】UITableView 8 自定义cell
- 【数组】Longest Consecutive Sequence
- Android UI 优化——使用HierarchyViewer工具
- 【N皇后&DFS】N-Queens II
- UIScrollView 和 UIPageControl实现页面循环播放
- IOS 警告框 (UIAlertView)的使用方法
- [💯原]IOS动画中的枚举UIViewAnimationOptions
- UITextField相关
- value的类型判断然后调用Date