Im trying to add a uibarbutton- Camera style to a uitableviewcell programmatically like so
but I dont see anything in the uitableviewcell
UIButton *newBtn=[UIButton buttonWithType:UIBarButtonSystemItemCamera];
[newBtn setFrame:CGRectMake(250,10,50,30)];
[newBtn addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[newBtn setEnabled:YES];
[cell addSubview:newBtn];
but when I use this code, I see a rounded rect button in the uitableviewcell
UIButton *newBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[newBtn setFrame:CGRectMake(250,10,50,30)];
[newBtn addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[newBtn setEnabled:YES];
[cell addSubview:newBtn];
Is there any way I can add a uibarbuttonstyle button or all I can do is add a uibutton rounded rect style to the uitableviewcell?
UIBarButtonItemis not the same asUIButton. It doesn’t even inherit fromUIView, so you can’t add it as a subview to other views. What happens when you callis that the
UIBarButtonSystemItemCameraconstant is of an invalid value forbuttonWithType:, so UIButton can’t decide which type of button to return – probably it just returns an empty, not configured one ornil.So there’s no easy solution to your problem. What you can do is, for example, take a screenshot of the Camera bar button item, then extract its image using some kind of image editor application, then set that image as the image of a custom
UIButtonlike this: