开发者

How to change the alpha value for the title of the UIButton in Iphone sdk?

I need to change the alpha value for the UIButton can any one suggest me how to do with it.

And the button code I written as:

UIView* buttonView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 100, 40)];
    buttonView.backgroundColor = [UIColor clearColor];

    backButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 100, 30)];
    [backButton setBackgroundImage:[UIImage imageNamed:@"backbutton_100.png"] forState:UIControlStateNormal];
    [backButton addTarget:self  action:@selector(backAction:)  forControlEvents:UIControlEventTouchUpInside];
    [backButton setTitle:@"  All Customers" forState:UIControlStateNormal];
    backButton.titleLabel.font = [UIFont boldSystemFontOfSize:12];      
    [buttonView addSubview:backButton];

    UIBarButtonItem* leftButton = [[UIBarButtonItem alloc] initWithCustomView:buttonView];
    self.navigationItem.leftBarButtonItem = leftButton;
    [leftButton release];

Thanks in advance. Monish.开发者_如何学Python


[backButton setTitleColor:[UIColor colorWithRed:0.3 green:0.6 blue:0.9 alpha:0.5]
//                                set 'alpha' to something less than 1. -----^^^
                 forState:UIControlStateNormal];


Swift 5 version of kennytm's answer:

backButton.setTitleColor(UIColor(red: 0.3, green: 0.6, blue: 0.9, alpha: 0.5), for: .normal)
IMPORTANT:
To animate this a `UIView.transition` on the `UIButton` is needed as `UIView.animate` won't work.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜