ios - আমি UIButton শিরোনাম রঙ পরিবর্তন করতে পারেন কিভাবে?
objective-c iphone (4)
আপনি UIButton
তৈরি করেছেন ViewController
, UIFont
, tintColor
এবং tintColor
পরিবর্তন করার জন্য নিম্নলিখিত উদাহরণ পদ্ধতি
উদ্দেশ্য গ
buttonName.titleLabel.font = [UIFont fontWithName:@"LuzSans-Book" size:15];
buttonName.tintColor = [UIColor purpleColor];
[buttonName setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
দ্রুতগতি
buttonName.titleLabel.font = UIFont(name: "LuzSans-Book", size: 15)
buttonName.tintColor = UIColor.purpleColor()
buttonName.setTitleColor(UIColor.purpleColor(), forState: .Normal)
Swift3
buttonName.titleLabel?.font = UIFont(name: "LuzSans-Book", size: 15)
buttonName.tintColor = UIColor.purple
buttonName.setTitleColor(UIColor.purple, for: .normal)
আমি প্রোগ্রাম্যাটিকভাবে একটি বাটন তৈরি .........।
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];
আমি কিভাবে শিরোনাম রঙ পরিবর্তন করতে পারেন?
আপনি এটি ব্যবহার করতে পারেন -[UIButton setTitleColor:forState:]
।
উদাহরণ:
উদ্দেশ্য গ
[buttonName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
সুইফ্ট 2
buttonName.setTitleColor(UIColor.blackColor(), forState: .Normal)
সুইফ্ট 3
buttonName.setTitleColor(UIColor.white, for: .normal)
richardchildan ধন্যবাদ
সুইফ্ট 3 দিয়ে, UIButton
একটি সেট setTitleColor(_:for:)
পদ্ধতি। setTitleColor(_:for:)
নিম্নলিখিত ঘোষণা আছে:
func setTitleColor(_ color: UIColor?, for state: UIControlState)
নির্দিষ্ট রাষ্ট্রের জন্য ব্যবহার করার জন্য শিরোনামের রঙ নির্ধারণ করে।
নিম্নলিখিত Playground কোডটি একটি UIViewController
UIbutton
তৈরি করতে এবং সেট setTitleColor(_:for:)
ব্যবহার করে setTitleColor(_:for:)
শিরোনাম রঙ পরিবর্তন করে setTitleColor(_:for:)
:
import UIKit
import PlaygroundSupport
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
// Create button
let button = UIButton(type: UIButtonType.system)
// Set button's attributes
button.setTitle("Print 0", for: UIControlState.normal)
button.setTitleColor(UIColor.orange, for: UIControlState.normal)
// Set button's frame
button.frame.origin = CGPoint(x: 100, y: 100)
button.sizeToFit()
// Add action to button
button.addTarget(self, action: #selector(printZero(_:)), for: UIControlEvents.touchUpInside)
// Add button to subView
view.addSubview(button)
}
func printZero(_ sender: UIButton) {
print("0")
}
}
let controller = ViewController()
PlaygroundPage.current.liveView = controller
UIViewController
তৈরি ইনস্ট্যান্স প্রদর্শন করার জন্য Show the Assistant Editor
> Timeline <Name of the page>.xcplaygroundpage
নির্বাচন করুন নির্বাচন করুন।
সুইফ্ট সমাধান 3 :
button.setTitleColor(UIColor.red, for: .normal)
এটি বাটন শিরোনাম রঙ সেট করা হবে।