UIbutton文字左 图片右

2018-07-04  本文已影响104人  iOS_Developer
//创建UIButton并设置约束
UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:moreButton];
[moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo (_titlesLabel);
        make.right.mas_equalTo (self).offset(-EDGE_WIDTH);
        make.width.mas_equalTo (60 * KWIDTH_IPHONE6_SCALE);
        make.height.mas_equalTo (24 * KHEIGHT_IPHONE6_SCALE);
    }];
    //设置button属性
    moreButton.backgroundColor = [UIColor whiteColor];
    [moreButton setTitle:@"更多" forState:UIControlStateNormal];
    moreButton.titleLabel.font = [UIFont pingFang_RegularWithSize:14.0];
    [moreButton setTitleColor:[UIColor color102] forState:UIControlStateNormal];
    
    [moreButton setImage:[UIImage imageNamed:@"arrowGrayRight"] forState:UIControlStateNormal];
    //设置内部文字 图片位置 文字左 图片右
    [moreButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -moreButton.imageView.bounds.size.width*1.2, 0, moreButton.imageView.bounds.size.width)];
    [moreButton setImageEdgeInsets:UIEdgeInsetsMake(0, moreButton.titleLabel.bounds.size.width*1.2, 0, -moreButton.titleLabel.bounds.size.width)];
    [moreButton addTarget:self action:@selector(moreButtonAction) forControlEvents:UIControlEventTouchUpInside];
上一篇下一篇

猜你喜欢

热点阅读