0
ピッカー表示の背景に3色の異なる色を設定したい 現在のピッカー(選択した項目)にある項目のバックグラウンド項目を1つ選択します。それ。ピッカーの背景色で異なる色を設定する方法
私はカラー(#01445)の16進数を持っているので、ピッカーの背景に設定する必要があります。これらの16進値を設定する方法。 また、このカラー(#014455)値をピッカーの選択項目に設定する必要があります。
myPickerView = [[UIPickerView alloc]init];
myPickerView.dataSource = self;
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
myPickerView.tag=1;
[myPickerView setBackgroundColor:[self colorFromHexString:@"#014455"]]; //set different color here with hex value
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
initWithTitle:@"Done" style:UIBarButtonItemStyleDone
target:self action:@selector(done:)];
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:
CGRectMake(0, self.view.frame.size.height-
myPickerView.frame.size.height-(self.view.frame.size.width/6.4),self.view.frame.size.width,50)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
[toolBar setBackgroundColor:[self colorFromHexString:@"#ff7a03"]]; // i have hex value #ff7a03 so i have to set here
NSArray *toolbarItems = [NSArray arrayWithObjects:
doneButton, nil];
[toolBar setItems:toolbarItems];
これは私が背景
-(UIColor *)colorFromHexString:(NSString *)hexString {
unsigned rgbValue = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexString];
[scanner setScanLocation:1]; // bypass '#' character
[scanner scanHexInt:&rgbValue];
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
}
実際に私はすでに16進数の色を設定する関数を作成しましたが、更新されたコードを見てください。しかし、今私の問題は私がピッカーから選択した行の背景色を実装したかったことです。 – vicky
私の答えは16時間前でした;)、今あなたのセルバックグラウンドの色を変更するために変更する必要がありますか? –
あなたはどうすればいいのでしょうか?@Reinier Melian – vicky