UIBarButtonItem icon white when added via IB, black when added programmatically

后端 未结 4 398
不知归路
不知归路 2020-12-30 12:59

When I add an icon to a UIBarButtonItem via the Interface Builder, the icon is displayed white. When I add the same icon file programmatically to another

4条回答
  •  星月不相逢
    2020-12-30 14:02

    In your code, you are setting an UIButton as the subview of an UIBarButtonItem. UIBarButtonItem is already a button, so you shouldn't add another button as the subview.

    Try this:

    UIImage *image = [UIImage imageNamed:@"icon.png"];
    rootViewController.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:image] autorelease];
    

提交回复
热议问题