UIButton颜色渐变 titleLabel字体不显示

1.设置字体大小后,titleLabel不显示

2.解决:字体大小设置方法在layer加载后执行

 *upButton = [UIButton buttonWithType:UIButtonTypeCustom];

    [viewaddSubview:upButton];

    [upButtonmas_makeConstraints:^(MASConstraintMaker*make) {

        make.left.equalTo(16);

        make.right.equalTo(-16);

        make.top.equalTo(26);

        make.height.equalTo(44);

    }];

    [upButtonsetTitle:stringforState:UIControlStateNormal];

    [upButtonsetTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    CAGradientLayer *gradientLayer = [CAGradientLayer layer];

    [gradientLayersetColors:@[(id)colorFromHexString(@"FA754B").CGColor,(id)colorFromHexString(@"FF2074").CGColor]];//渐变数组

    gradientLayer.startPoint=CGPointMake(0,0);

    gradientLayer.endPoint=CGPointMake(1,0);

    gradientLayer.locations=@[@(0),@(1.0)];//渐变点

    gradientLayer.frame=CGRectMake(0,0,200,44);

    [upButton.layeraddSublayer:gradientLayer];

    upButton.titleLabel.font= [UIFontsystemFontOfSize:18];

你可能感兴趣的:(UIButton颜色渐变 titleLabel字体不显示)