美文网首页
button使用归整(不常用到的属性)

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

作者: 夜未殇 | 来源:发表于2017-03-30 17:16 被阅读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];
    

    相关文章

      网友评论

          本文标题:button使用归整(不常用到的属性)

          本文链接:https://www.haomeiwen.com/subject/jhjpottx.html