[btn setImage:imgNor forState:UIControlStateNormal]; [btn setImage:imgSel forState:UIControlStateSelected]; [btn setTitle:[arrLabel objectAtIndex:i] forState:UIControlStateNormal]; [btn setTitleColor:kCOLOR_TABBARNOR forState:UIControlStateNormal]; […
项目中经常遇到按钮改变文字和图片位置的情况,所以尝试写一个 button 的分类: 参照连接 http://blog.csdn.net/dfqin/article/details/37813591 import Foundation import UIKit /*枚举 设置 图片的位置*/ enum ButtonImagePosition : Int{ case Positionleft case PositionBottom case PositionRight } extension UIB…
LaunchImage AppIcon 分别拖拉至Images.scassets  对应的LaunchImage和AppIcon就可以设置 启动图片和AppIcon图片…
UIButton * button =[UIButton buttonWithType:UIButtonTypeCustom];button.titleLabel.adjustsFontSizeToFitWidth = YES;…
// button.titleLabel.textAlignment = NSTextAlignmentLeft; 这句无效 button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 在通过代码设置文字的对齐方式时  我们会常识性的使用button.titleLabel.textAlignment = NSTextAlignmentLeft;这个方法 但发现这个方法并没有什么效果,因为这只是让标签中的…
方法一. -(CGRect)imageRectForContentRect:(CGRect)contentRect {    return CGRectMake(self.width - kImageW, 0, kImageW, self.height);}-(CGRect)titleRectForContentRect:(CGRect)contentRect {    return CGRectMake(0, 0, self.width - kImageW, self.height);} 方法…
-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;…
实现如图所示效果: 这是一个UIButton,需要改变image和title相对位置. 解决如下: //设置文字偏移:向下偏移图片高度+向左偏移图片宽度 (偏移量是根据[图片]大小来的,这点是关键)btnLeft.titleEdgeInsets = UIEdgeInsets(top: btnLeft.imageView!.frame.size.height, left: -btnLeft.imageView!.frame.size.width, bottom: 0, right: 0) //设置…
1. 添加图片+文字/文字+图片 ,不分前后,图片默认在文字前边 加空格隔开 UIButton * button =[[UIButton alloc] initWithFrame:CGRectMake(, , , )]; button.backgroundColor =[UIColor grayColor]; //图片 [button setImage:[UIImage imageNamed:@"but"] forState:UIControlStateNormal]; //文字 [b…
经查阅资料及尝试,最终解决了在图片和文字垂直排列的情况下,如果文字长度变化会导致图片位置变动的问题,最开始采用了网上比较多的做法,做法如下: @interface UIButton (UIButtonExt)   - (void)centerImageAndTitle:(float)space;   - (void)centerImageAndTitle;   @end   @implementation UIButton (UIButtonExt)   - (void)centerImageA…