প্রতিনিধি পদ্ধতিতে একটি ফাংশন রয়েছে যা আরও মার্জিত:
উদ্দেশ্য গ:
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *title = @"sample title";
NSAttributedString *attString =
[[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
return attString;
}
আপনি যদি বাছাই বারের রংগুলিও পরিবর্তন করতে চান তবে আমি দেখতে পেলাম যে 180 টির বাছাইকারী উচ্চতার জন্য, 35 ডিগ্রিবিশিষ্ট বিস্তৃত ভিউটিতে আমাকে 2 টি আলাদা যুক্ত UIViews
করতে হয়েছিল UIPickerView
।
সুইফট 3:
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let string = "myString"
return NSAttributedString(string: string, attributes: [NSForegroundColorAttributeName:UIColor.white])
}
সুইফট 4:
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let string = "myString"
return NSAttributedString(string: string, attributes: [NSAttributedStringKey.foregroundColor: UIColor.white])
}
সুইফট 4.2:
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let string = "myString"
return NSAttributedString(string: string, attributes: [NSAttributedString.Key.foregroundColor: UIColor.white])
}
আপনি যখন পদ্ধতিটি ব্যবহার করবেন তখন মনে রাখবেন: ব্যবহারের সময় titleForRowInComponent()
কখনই ডাকা হয় না সেহেতু আপনার প্রয়োগ করার দরকার নেই attributedTitleForRow()
।