有一个委托方法,通过它可以实现期望的输出。
的Objective-C:
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *strTitle = @"YourTitle";
NSAttributedString *attString = [[NSAttributedString alloc] initWithString:strTitle attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
return attString;
}
斯威夫特:
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let strTitle = "YourTitle"
let attString = NSAttributedString(string: strTitle, attributes: [NSForegroundColorAttributeName : UIColor.whiteColor()])
return attString
}
希望这将帮助你:)
- (UIView的*)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,pickerView.frame.size.width,44)]; label.backgroundColor = [UIColor clearColor]; label.textColor = [UIColor WhiteColor]; label.font = [UIFont fontWithName:@“HelveticaNeue-Bold”size:18]; label.text = [NSString stringWithFormat:@“%c”,65 + row]; // ASCII 65是“A” 返回标签; } 明白了谢谢 – Nimmy