SORU
7 EKİM 2013, PAZARTESİ


Nasıl iOS 7 altında bir UİPickerView metin rengini değiştirebilirim?

pickerView:viewForRow:forComponent:reusingView yöntemi farkındayım, ama view kullanırken reusingView: geçiyor nasıl farklı metin rengi kullanmak değiştirebilirim? Eğer view.backgroundColor = [UIColor whiteColor]; kullanırsam görünümleri yok artık.

CEVAP
6 Kasım 2013, ÇARŞAMBA


Daha zarif temsilci yöntemi bir işlevi vardır:

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSString *title = @"sample title";
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

return attString;

}

Eğer seçim çubuğu renkleri de değiştirmek isterseniz, görünüm UİPickerView içeren 2 ayrı UİViews eklemek zorunda bulundu, aralıklı 35 ayrı 180 seçici bir yükseklik için puan.

Swift: güncelleştirin

func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
    let string = "myString"
    return NSAttributedString(string: string, attributes: [NSForegroundColorAttributeName:UIColor.whiteColor()])
}

Bu yöntemi kullandığınızda unutmayın: attributedTitleForRow() kullanırken asla denir titleForRowInComponent() uygulamaya gerek yok.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Edgar flores

    Edgar flores

    7 HAZİRAN 2006
  • Helder Barreto

    Helder Barre

    22 Mayıs 2006
  • Howcast

    Howcast

    4 EKİM 2007