UIButton(改变Title和image位置)
UIButton *btn = [[UIButton alloc] init]; [btn setFrame:frame]; [btn setTitleColor:titleColor forState:UIControlStateNormal]; [btn setTitle:title forState:UIControlStateNormal]; [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; [btn setImage:normalI forState:UIControlStateNormal]; //按钮内容对齐方式 btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; //按钮image位置 btn.imageEdgeInsets = UIEdgeInsetsMake(0,btn.titleLabel.bounds.size.width, 0,-btn.titleLabel.bounds.size.width); //按钮title的位置 btn.titleEdgeInsets = UIEdgeInsetsMake(0,-btn.imageView.image.size.width, 0, btn.imageView.image.size.width); //按钮图片自适应 btn.imageView.contentMode= UIViewContentModeScaleAspectFit;
将来的自己,会感谢现在不放弃的自己!