假设有按钮rButton的 imageEdgeInsets和contentEdgeInsets可以设置按钮的标题和图片的位置,如下代码,设置标题居右
NSString * rBtnTitle = @"删除"; CGSize size = [rBtnTitle sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}]; NSLog(@"size = %@",NSStringFromCGSize(size)); CGFloat leftPadding = CGRectGetWidth(rBtn.frame) - size.width; rBtn.contentEdgeInsets = UIEdgeInsetsMake(0, leftPadding, 0, 0);