zoukankan      html  css  js  c++  java
  • 如何自定义UIPickerView中文本的大小和文本靠左或靠右显示?

    需要重写UIPickerView中的

     1 -(UIView*)pickerView:(UIPickerView*)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view 

    方法

    示例代码如下

     1 //自定义uipickerview中的文字大小
     2 -(UIView*)pickerView:(UIPickerView*)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
     3 {
     4     UILabel *myView=nil;
     5     
     6     myView=[[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 264, 30)];
     7     myView.textAlignment=NSTextAlignmentRight;
     8     
     9     if (pickerView==self.SourcePicker) {
    10         myView.text=[_SourcePickerArray objectAtIndex:row];
    11         
    12     }else{
    13         myView.text=[_RoomPickerArray objectAtIndex:row];
    14     }
    15     myView.font=[UIFont systemFontOfSize:17];
    16     myView.textColor=[UIColor blackColor];
    17     myView.backgroundColor=[UIColor clearColor];
    18     return  myView;
    19     
    20 }

    另外注意,ios6之前调整文本靠左或者靠右对齐的代码为

     1 mylabel.textAlignment= UITextAlignmentCenter; 

    在ios7以上版本需要改为

     1 mylabel.textAlignment=NSTextAlignmentCenter; 

  • 相关阅读:
    超链接与图像
    24
    2018-02-24
    2018-02-23
    2018-02-05(jQuery)
    2018-01-29(jQuery)
    2018-01-29(Bootstrap)
    2018-01-29(HTML+CSS)
    451. 根据字符出现频率排序
    550.键盘行
  • 原文地址:https://www.cnblogs.com/dongweiq/p/3653440.html
Copyright © 2011-2022 走看看