调整按钮的子控件titleLable和imageView的间距的属性和用法
self.titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; self.titleBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0); self.titleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0); self.titleBtn.imageEdgeInsets = UIEdgeInsetsZero;
- (void)horizontalAlgin:(int)spacing { CGFloat insetAmount = spacing / 2.0; self.imageEdgeInsets = UIEdgeInsetsMake(0, -insetAmount, 0, insetAmount); self.titleEdgeInsets = UIEdgeInsetsMake(0, insetAmount, 0, -insetAmount); } -(void)verticalAlignWithSpace:(int)spacing topSpacing:(int)topSpacing { CGSize imageSize = self.imageView.image.size; self.titleEdgeInsets = UIEdgeInsetsMake(topSpacing, - imageSize.width, - (imageSize.height + spacing + topSpacing), 0.0); CGSize titleSize; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { titleSize = [[self titleForState:self.state] sizeWithAttributes:@{NSFontAttributeName: self.titleLabel.font}]; } else { titleSize = self.titleLabel.frame.size; } self.imageEdgeInsets = UIEdgeInsetsMake(topSpacing - (titleSize.height + spacing), 0.0, -topSpacing, - titleSize.width); }