Hel*_*rld 186 iphone objective-c uibutton ios
我以编程方式创建一个按钮..........
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
Run Code Online (Sandbox Code Playgroud)
如何更改标题颜色?
Ben*_*ieb 507
你可以-[UIButton setTitleColor:forState:]用来做这件事.
例:
Objective-C的
[buttonName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
斯威夫特2
buttonName.setTitleColor(UIColor.blackColor(), forState: .Normal)
Run Code Online (Sandbox Code Playgroud)
斯威夫特3
buttonName.setTitleColor(UIColor.white, for: .normal)
Run Code Online (Sandbox Code Playgroud)
Anb*_*hik 23
您创建的UIButton添加了ViewController,下面的实例方法来改变UIFont,tintColor和TextColor的UIButton
Objective-C的
buttonName.titleLabel.font = [UIFont fontWithName:@"LuzSans-Book" size:15];
buttonName.tintColor = [UIColor purpleColor];
[buttonName setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
迅速
buttonName.titleLabel.font = UIFont(name: "LuzSans-Book", size: 15)
buttonName.tintColor = UIColor.purpleColor()
buttonName.setTitleColor(UIColor.purpleColor(), forState: .Normal)
Run Code Online (Sandbox Code Playgroud)
Swift3
buttonName.titleLabel?.font = UIFont(name: "LuzSans-Book", size: 15)
buttonName.tintColor = UIColor.purple
buttonName.setTitleColor(UIColor.purple, for: .normal)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
162947 次 |
| 最近记录: |