中心UIPickerView文本(Center UIPickerView Text)

编程入门 行业动态 更新时间:2024-10-08 10:49:15
中心UIPickerView文本(Center UIPickerView Text)

所以我有一个uipickerview,行只包含数字0-24,它看起来有点傻,因为数字保持一致,留下了很大的差距,在选择器视图的右边。

在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?

最满意答案

- (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 = NSTextAlignmentCenter; //Changed to NS as UI is deprecated. label.backgroundColor = [UIColor clearColor]; [label autorelease]; return label; }

或这样的东西。

- (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 = NSTextAlignmentCenter; //Changed to NS as UI is deprecated. label.backgroundColor = [UIColor clearColor]; [label autorelease]; return label; }

or something like this.

更多推荐

本文发布于:2023-07-19 23:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1188568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   中心   Text   UIPickerView   Center

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!