Skip to content

Instantly share code, notes, and snippets.

@flashlib
Created September 3, 2013 02:52
Show Gist options
  • Save flashlib/6419226 to your computer and use it in GitHub Desktop.
Save flashlib/6419226 to your computer and use it in GitHub Desktop.
UIPickerView居中
// 6.0以上
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *text = [NSString stringWithFormat:@"R%d C%d", row, component];
NSMutableAttributedString *as = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle *mutParaStyle=[[NSMutableParagraphStyle alloc] init];
mutParaStyle.alignment = NSTextAlignmentCenter;
[as addAttribute:NSParagraphStyleAttributeName value:mutParaStyle range:NSMakeRange(0,[text length])];
return as;
}
// 6.0以前
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 37)];
label.text = [NSString stringWithFormat:@"something here"];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
[label autorelease];
return label;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment