SORU
17 EYLÜL 2013, Salı


Özel UİBarButtonİtem düzgün olarak sol veya sağ gezinti çubuğu öğeleri kullanıldığında iOS 7 uyumlu görünüm

Aşağıdaki kodu iOS 6 ile çalışır:

UIButton *myButton = nil;
myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.bounds = CGRectMake(0,0,44,30);
// setup myButton's images, etc.

UIBarButtonItem *item = nil;
item = [[UIBarButtonItem alloc] initWithCustomView:customButton];

Bu düğme uyumlu olması gerekirdi

Normal positioning

Ancak, iOS 7, düğme çok fazla piksel sağa ya da sola sapmış görünüyor:

Incorrect positioning on iOS 7

Nasıl benim özel düğme öğeleri düzgün hizalanmasını bar alabilir miyim?

CEVAP
17 EYLÜL 2013, Salı


Bu hatayı düzeltmek için alignmentRectInsets geçersiz kılabilirsiniz, böylece UİButton alt gerekir. Benim test pozitif bir ofset ya da pozitif bir sol ya da bir UİEdgeİnsets, düğme konumuna göre mahsup iade etmek gerekir. Bu numaralar bana (en azından bir tanesi negatif, sağduyu göre olmalıdır) için hiçbir mantıklı, ama bu gerçekten işe yarıyor nedir:

- (UIEdgeInsets)alignmentRectInsets {
    UIEdgeInsets insets;
    if (IF_ITS_A_LEFT_BUTTON) {
        insets = UIEdgeInsetsMake(0, 9.0f, 0, 0);
    } 
    else { // IF_ITS_A_RIGHT_BUTTON
        insets = UIEdgeInsetsMake(0, 0, 0, 9.0f);
    }
    return insets;
}

@Ben alignmentRectİnsets ayarlamayı deneyin önerdiğin için zev için özel teşekkürler.

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BigBoyTV

    BigBoyTV

    25 EYLÜL 2013
  • Howcast

    Howcast

    4 EKİM 2007
  • sWooZie

    sWooZie

    9 ŞUBAT 2006