Jump to content

UIBarButtonItem with UIButton


2 posts in this topic

Recommended Posts

Hi,

 

I want to change the color of my UIBarButtonItem to RED but I think there is no direct method or property to that.

 

So, I am doing this:

 

UIButton *pCustomButton = [uIButton buttonWithType:UIButtonTypeRoundRect];

[pCustomButton addTarget:self action:@selector(Logout:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *pLogOut = [[uIBarButtonItem alloc] initWithCustomView:pCustomButton];

pLogOut.title = @"LogOut";

self.navigationItem.leftBarButtonItem = pLogOut;

 

But my button is not appearing on the navigation bar. Any Ideas? what should I do now?

 

Thanks in advance

MacDev

Link to comment
Share on other sites

Hi,

 

I want to change the color of my UIBarButtonItem to RED but I think there is no direct method or property to that.

 

So, I am doing this:

 

UIButton *pCustomButton = [uIButton buttonWithType:UIButtonTypeRoundRect];

[pCustomButton addTarget:self action:@selector(Logout:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *pLogOut = [[uIBarButtonItem alloc] initWithCustomView:pCustomButton];

pLogOut.title = @"LogOut";

self.navigationItem.leftBarButtonItem = pLogOut;

 

But my button is not appearing on the navigation bar. Any Ideas? what should I do now?

 

Thanks in advance

MacDev

 

You have to create a frame and then attach the frame to the button before adding it to the UIBarButtonItem.

 

Like this: pCustomButton.frame=CGRectMake(0.0, 100.0, 50.0, 30.0)

Link to comment
Share on other sites

 Share

×
×
  • Create New...