0

我允许当用户从 ActionSheetPicker 选择字体颜色时,文本的字体颜色会在颜色发生变化时发生变化。我使用第三方库https://github.com/skywinder/ActionSheetPicker-3.0
我该怎么做?
我必须更改第三方库或自定义 ActionSheetPicker。

是否有任何值更改事件来实现此功能?

这是我真正想要的图像。 http://i.stack.imgur.com/J2bz0.png

4

2 回答 2

0

在 done 块中,showPickerWithTitle:rows:initialSelection:doneBlock:cancelBlock:origin 您可以知道选择了哪个索引或值,并相应地更改文本的颜色。

[ActionSheetStringPicker showPickerWithTitle:@"Select a Color"
                                        rows:colors
                            initialSelection:0
                                   doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {                                       
                                      yourLabel.textColor = ...
                                    }
                                 cancelBlock:^(ActionSheetStringPicker *picker) {
                                      NSLog(@"Block Picker Canceled");
                                    }
                                      origin:sender];
于 2015-09-19T11:34:19.433 回答
0

首先在你的项目中导航到 Picker 文件夹并打开ActionSheetStringPicker.m 然后添加下面的代码

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

     NSString *str_lbl = (self.data)[(NSUInteger) row];

    //NSLog(@"////////%@",obj);

    UILabel *label = (UILabel*) view;
    if (label == nil)
    {
        label = [[UILabel alloc] init];
    }

    [label setText:str_lbl];

    // This part just colorizes everything, since you asked about that.

    [label setTextColor:[UIColor whiteColor]];

    if ([str_lbl isEqualToString:@"Red"])
    {
        [label setTextColor:[UIColor redColor]];
    }
    else if([str_lbl isEqualToString:@"Green"])
    {
        [label setTextColor:[UIColor greenColor]];
    }
    else if([str_lbl isEqualToString:@"Blue"])
    {
        [label setTextColor:[UIColor blueColor]];
    }
    else if([str_lbl isEqualToString:@"Orange"])
    {
        [label setTextColor:[UIColor orangeColor]];
    }
    else
    {

    }

   // [label setBackgroundColor:[UIColor blackColor]];
    CGSize rowSize = [pickerView rowSizeForComponent:component];
    CGRect labelRect = CGRectMake (0, 0, rowSize.width, rowSize.height);
    [label setFrame:labelRect];

    return label;
}
于 2015-09-19T11:35:30.470 回答