系统提供的类的readonly属性可通过KVC进行赋值
UITabBarController.h @interface UITabBarController : UIViewController <UITabBarDelegate, NSCoding> @property(nonatomic,readonly) UITabBar *tabBar @end //如上述代码,UITabBarController类有一个只读的属性tabBar,想用自定义的WZTabBar对象来替换UITabBarController的tabBar属性,则不能直接赋值,可采用KVC直接对UITabBarController类的_tabBar实例变量进行赋值。 具体代码如下: WZTabBar *tabBar = [[WZTabBar alloc]init]; //self.tabBar = tabBar; 报错,readonly不能赋值,采用KVC赋值 [self setValue:tabBar forKey:@"tabBar"];