UIButton进阶

//创建一个button

UIButton *credit = [UIButton buttonWithType:UIButtonTypeSystem];

    [actionView addSubview:credit];

// 使用masonry约束

    [credit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(actionView).offset(50 * PROPORTION);
        make.left.equalTo(actionView).offset(62 * PROPORTION);
        make.height.equalTo(@(13 * PROPORTION));
        make.right.equalTo(actionView).offset(-62 * PROPORTION);

    }];

// 同时设置名称及图片,并且靠左显示

    [credit setTitle:@"信用等级" forState:UIControlStateNormal];

// 设置图片时需要设置图片显示为原始图片,不跟随系统设置变蓝

    [credit setImage:[IMAGENAMED(@"page_jjrdp_grxx_img_xydj") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [credit setTitleColor:TitleText_Color forState:UIControlStateNormal];
    // 设置文字与图片居左显示

    credit.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//居左显示

 // 设置文字距离图片的间距
    credit.titleEdgeInsets = UIEdgeInsetsMake(0, 9 * PROPORTION, 0, 0);
    // 设置图片距离左边的间距
//    credit.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);

你可能感兴趣的:(UI)