如何更改 UIPicker 中字符的大小

发布于 2024-11-19 21:39:16 字数 620 浏览 4 评论 0原文

我正在尝试居中并更改 UIPicker 内文本的大小,但不确定如何...我认为这可能发生在其中一种方法中,很可能是第一种...

- (NSString*)pickerView:(UIPickerView*)pv titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [[NSString stringWithFormat:@"%x",row ] uppercaseString]; //Sets picker options as an Uppercase Hex value
}


#pragma mark UIPickerViewDataSource methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pv
{
    return 5; //5 columns in the picker
}

- (NSInteger)pickerView:(UIPickerView*)pv numberOfRowsInComponent:(NSInteger)component
{
    return 16;
}

有人知道如何做到这一点吗?我环顾四周,但文档相当薄......

I am trying to center and change the size of the text inside my UIPicker but am not sure how... I think it might happen in one of these methods, most likely the first...

- (NSString*)pickerView:(UIPickerView*)pv titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [[NSString stringWithFormat:@"%x",row ] uppercaseString]; //Sets picker options as an Uppercase Hex value
}


#pragma mark UIPickerViewDataSource methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pv
{
    return 5; //5 columns in the picker
}

- (NSInteger)pickerView:(UIPickerView*)pv numberOfRowsInComponent:(NSInteger)component
{
    return 16;
}

Dose anyone one know how this can be done? I have looked around but the documentation is fairly thin...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

脸赞 2024-11-26 21:39:17

Johns,

就像在表视图中一样,您无法更改通常在 titleForRow 委托方法中设置的默认标题的字体属性,而是必须使用以下方法:

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component

这里您可以使用自定义 UILabel 创建一个 UIView 并设置Label 的字体大小、颜色和其他属性。

此方法在 Apple 的 UIPickerView 类参考< /a>

希望这对您有帮助!

Johns,

As in Table Views, you can't change the font attributes of the default title that you usually set in the titleForRow delegate method, instead you have to use the following method:

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component

Here you can create an UIView with a custom UILabel and set the Label's font size, color and other attributes.

This method is described in Apple's UIPickerView Class Reference

Hope this help you!

暖伴 2024-11-26 21:39:17

现在,在 iOS 6 中,您可以使用 NSAttributedStrings 自定义标题文本(尽管我认为这不能让您轻松地将文本居中)。

新的 UIPickerViewDelegate 方法可让您返回属性字符串而不是普通字符串:

(NSAttributedString *)pickerView:(UIPickerView *)pickerView attributeTitleForRow:(NSInteger)row forComponent:(NSInteger)component

NSAttributedString UIKit 添加页面包含所有内容的列表您可以控制的角色属性:
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/Reference/Reference.html#//apple_ref/doc/uid/TP40011688

Now with iOS 6 you can use NSAttributedStrings to customize the title text (though I don't think this lets you easily center the text).

A new UIPickerViewDelegate method lets you return an attributed string instead of a plain vanilla string:

(NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component

The NSAttributedString UIKit additions page has a list of all the character attributes you can control:
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/Reference/Reference.html#//apple_ref/doc/uid/TP40011688

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文