button使用归整(不常用到的属性)

2017-03-30  本文已影响0人  夜未殇

1、调整image以及title的位置

//顺序是上、左、下、右,比如第一个是title向左移动10,image向右移动10
btn.titleEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
btn.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);

2、设置button中title的对齐方式

//纵向对齐方式
typedef NS_ENUM(NSInteger, UIControlContentVerticalAlignment) {
    UIControlContentVerticalAlignmentCenter  = 0,
    UIControlContentVerticalAlignmentTop     = 1,
    UIControlContentVerticalAlignmentBottom  = 2,
    UIControlContentVerticalAlignmentFill    = 3,
};
//横向对齐方式
typedef NS_ENUM(NSInteger, UIControlContentHorizontalAlignment) {
    UIControlContentHorizontalAlignmentCenter = 0,
    UIControlContentHorizontalAlignmentLeft   = 1,
    UIControlContentHorizontalAlignmentRight  = 2,
    UIControlContentHorizontalAlignmentFill   = 3,
};
//例:左对齐
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

3、读取title的值

NSString *str = [btn titleForState:UIControlStateNormal];
上一篇下一篇

猜你喜欢

热点阅读