`

UIActionSheet添加UIPickerView.

阅读更多

 今天写了一个ActionSheet添加的UIPickerView的程序,搜索了很多的资料

- (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