So I have a uipickerview with rows that only contain the number 0-24 and it looks a bit silly since the numbers are left aligned leaving a huge gap on the right of the pickerview.
Is there an easy way to center align text in a uipickerview?
So I have a uipickerview with rows that only contain the number 0-24 and it looks a bit silly since the numbers are left aligned leaving a huge gap on the right of the pickerview.
Is there an easy way to center align text in a uipickerview?
Just set the width to the width of the view and the text will center automatically:
Remember, the view in
is actually a UITableViewCell, so you can work with it like:
Below one also working fine -
Cheers!!
A little easier now in iOS 6... There's a new method you can implement to return an attributed string... And you can define alignment in attributed strings.
or something like this.
You can implement this delegate method, which returns a CGFloat
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
This is called on the picker view to determine row width.