`
janedoneway
  • 浏览: 569880 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

UIActionSheet添加UIPickerView.

 
阅读更多

From: http://tsyouaschen.iteye.com/blog/972683

- (void)configurePickersAndActionSheets {
    CGRect pickerFrame;

    if ((self.interfaceOrientation == UIInterfaceOrientationPortrait) ||
        (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) {
        pickerFrame = CGRectMake(0, 180, 0, 0);
    } else {
        pickerFrame = CGRectMake(0,180,480,200);
    }
    self.areaActionSheet = [[[UIActionSheet alloc] initWithTitle:@"Area" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Use",NULL] autorelease];
    self.areaPicker = [[[UIPickerView alloc] initWithFrame:pickerFrame] autorelease];
    self.areaPicker.delegate = self;
    self.areaPicker.showsSelectionIndicator = YES;
    [self.areaActionSheet addSubview:areaPicker];
}
上面的代码就是横屏和纵屏的大小设置 
 if ((self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
        (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
        [actionSheet setBounds:CGRectMake(0, 0, 480, 480)];
    } else {
        [actionSheet setBounds:CGRectMake(0, 0, 320, 618)];
    }
此处用来设置actionsheet的大小  
具体的添加PickerView如下:
UIActionSheet 
*
menu 
=
 
[
[
UIActionSheet alloc
]
 


initWithTitle
:
[
currentData objectAtIndex
:
0
]
 

delegate
:
self
cancelButtonTitle
:
@
"Done"

destructiveButtonTitle
:
@
"Cancel"

otherButtonTitles
:
nil
]
;

 

UIPickerView * pickerView =  [ [ UIPickerView   alloc] initWithFrame: CGRectMake( 0,40,480,200) ] ;

pickerView.delegate  =  self; pickerView.showsSelectionIndicator  =   YES ;      

[ menu addSubview: pickerView] ; [ menu showInView: self.view] ; [ menu setBounds: CGRectMake( 0,0,480, 320) ] ;

[ pickerView release] ; [ menu release] ;

 

OK这个就完成了ActionSheet的操作,可能你还会有一个问题就是在UIPickerView如何设置显示下拉框的

字体大小,即改变显示数组中的字体大小: 

需要重写实现如下方法 

- (UIView *)pickerView:(UIPickerView *)pickerView 

viewForRow:(NSInteger )row 

  forComponent:(NSInteger )component 

  reusingView:(UIView *)view

 

        UILabel  *pickerLabel = (UILabel  *)view ;

       if  ((pickerLabel == nil ) || ([pickerView class ] != [UILabel  class ])) {

CGRect  frame = CGRectMake (0027032 );

pickerLabel = [[UILabel  allocinitWithFrame :frame];

pickerLabel. textAlignment  = UITextAlignmentLeft;

pickerLabel. backgroundColor = [ UIColor  clearColor ];

pickerLabel.font  = [UIFont  boldSystemFontOfSize :18 ];

 

     if  (component == kStateComponent ) {

pickerLabel. textAlignment  =  UITextAlignmentCenter;

pickerLabel.text  = [self .states  objectAtIndex :row];

    }

   else  if (component == kZipComponent ){

       pickerLabel. textAlignment  = UITextAlignmentLeft;

       pickerLabel.text  = [self .zips  objectAtIndex :row];

   }

   pickerLabel.textColor  = [UIColor  blackColor ];

   return  pickerLabel; 

}

return  0 ;

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics