Created
September 3, 2013 02:52
-
-
Save flashlib/6419226 to your computer and use it in GitHub Desktop.
UIPickerView居中
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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