Thursday, September 5, 2013

How to customize add new item button in the left of UITableView

How to customize add new item button in the left of UITableView

I have an application which shows files and folders in a UITableView.
I used the following code to customize done button and add new folder
button.Both of them are UIBarButtonItem.
doneButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
action:@selector(donePressed)];
[doneButton setTitleTextAttributes:
dictionaryOfTitleTextAttributes
forState:UIControlStateNormal];
addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self
action:@selector(createFolder)];
[addButton setTitleTextAttributes:
dictionaryOfTitleTextAttributes
forState:UIControlStateNormal];
[addButton setBackButtonBackgroundImage:[[UIImage
imageWithCGImage:[UIImage imageNamed:@"List/newfolder-normal.png"].CGImage
scale:2 orientation:UIImageOrientationDown]
resizableImageWithCapInsets:UIEdgeInsetsMake(4, 14, 4, 14)]
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[addButton setBackgroundImage:[[UIImage imageWithCGImage:[UIImage
imageNamed:@"List/newfolder-touched.png"].CGImage scale:2
orientation:UIImageOrientationDown]
resizableImageWithCapInsets:UIEdgeInsetsMake(4, 14, 4, 14)]
forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
[doneButton setBackgroundImage:[[UIImage imageWithCGImage:[UIImage
imageNamed:@"List/done-normal.png"].CGImage scale:2
orientation:UIImageOrientationDown]
resizableImageWithCapInsets:UIEdgeInsetsMake(4, 14, 4,
14)]forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[doneButton setBackgroundImage:[[UIImage imageWithCGImage:[UIImage
imageNamed:@"List/done-touched.png"].CGImage scale:2
orientation:UIImageOrientationDown]
resizableImageWithCapInsets:UIEdgeInsetsMake(4, 14, 4,
14)]forState:UIControlStateHighlighted
barMetrics:UIBarMetricsDefault];
As you see they use the same code and both are enabled in editing mode but
the addButton is not customized and remain as ios default buttons.
What would be the problem?

No comments:

Post a Comment