UIPickerView中的自动换行 [英] Word wrap in UIPickerView
本文介绍了UIPickerView中的自动换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UIPickerView,我想把文字换行。
这是我的代码:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
if (component == 0 ){
UILabel * lView =(UILabel *)视图;
if (!tView){
tView = [[UILabel alloc] init];
[tView setFont:[UIFont systemFontOfSize: 15 ]];
tView.numberOfLines = [种姓数];
}
tView.text = [categorie objectAtIndex:row];
return tView;
}
else {
UILabel * lView =(UILabel *)view;
if (!sView){
sView = [[UILabel alloc] init];
[sView setFont:[UIFont systemFontOfSize: 15 ]];
sView.numberOfLines = [subCat count];
}
sView.text = [subCat objectAtIndex:row];
return sView;
}
}
我尝试设置sView.numberOfLines = 0; (这通常是你如何将UILabel设置为自动换行,或者有超过1行)但是没有用。
解决方案
你还必须设置如 Stackoverflow 中所述的breakmode。如果你想进一步这个也可能很有趣。
I have a UIPickerView, and I would like to make the text word wrap.
Here is my code:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
if (component == 0) {
UILabel *lView = (UILabel *)view;
if (!tView) {
tView = [[UILabel alloc] init];
[tView setFont:[UIFont systemFontOfSize:15]];
tView.numberOfLines = [categorie count];
}
tView.text = [categorie objectAtIndex:row];
return tView;
}
else {
UILabel *lView = (UILabel *)view;
if (!sView) {
sView = [[UILabel alloc] init];
[sView setFont:[UIFont systemFontOfSize:15]];
sView.numberOfLines = [subCat count];
}
sView.text = [subCat objectAtIndex:row];
return sView;
}
}
I tried setting sView.numberOfLines = 0; (which is how you would normally set a UILabel to word wrap, or have more than 1 line) but that didn't work.
解决方案
You must also set the breakmode as described on Stackoverflow. If you want to go further this may also be interesting.
这篇关于UIPickerView中的自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文