UIAppearance setTranslucent error: Illegal property type, c for appearance setter, _installAppearanceSwizzleForSetter

前端 未结 4 434
日久生厌
日久生厌 2021-01-04 04:26

Trying out iOS 7 did:

[[UINavigationBar appearance] setTranslucent:NO];

Got crash and error:

*** Terminating app due to          


        
4条回答
  •  走了就别回头了
    2021-01-04 04:53

    I solved it with my own category so that I can still use UIAppearance in something like the normal manner.

    @interface UINavigationBar (MMTranlucenceUIAppearance)
    @property(nonatomic,assign,getter=isMMTranslucent) NSInteger LYTranslucent NS_AVAILABLE_IOS(3_0) UI_APPEARANCE_SELECTOR;  // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
    @end
    
    
    @implementation UINavigationBar (MMTranlucenceUIAppearance)
    
    // it appears that UIAppearance fails with BOOL
    -(NSInteger)isMMTranslucent
    {
        return self.translucent ? 0 : 1;
    }
    
    -(void)setMMTranslucent:(NSInteger)translucent
    {
        self.translucent = (translucent == 0) ? NO : YES;
    }
    
    @end
    

提交回复
热议问题