Sunday, February 03, 2013

Use an image as your UIBarButtonItem

Using an image as your UIBarButtonItem in your navigationcontroller bar can only be achieved by using a common UIButton as the BarButtonItem's custom view.

This is an example on how you can achieve that. It takes a target, selector and image name and returns a UIBarButtonItem as an image.

+(UIBarButtonItem*) getBarButton:(id)target withSelector:(SEL)selector andImage:(NSString*)imageName
{
    //Create image
    UIImage *image = [UIImage imageNamed:imageName];
    
    //Create UIButton with the imag
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
    [button setImage:image forState:UIControlStateNormal];
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];

    //Create UIBarButtonItem with customview button
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    return barButton;
}

12 comments:

tom said...

nice

essaykings.co.uk said...

This proved out to be extremely useful in terms of home assignment at the university! I like the idea of your blog very much!

kevin antony said...

I appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog. All the best.


rpa Training in annanagar

blue prism Training in annanagar

automation anywhere Training in annanagar

iot Training in annanagar

rpa Training in marathahalli

blue prism Training in marathahalli

automation anywhere Training in marathahalli

blue prism training in jayanagar

automation anywhere training in jayanagar

Pankaj Singh said...

Thank you much for this tutorial; this is informative and valuable blog. Visit for
Europe Honeymoon Packages

Veav by nimisha priya said...

Very nice post.
buy tops for girls

https://amantoothtown.blogspot.com/ said...

Great..thanks for sharing this information..
dentist in vasant kunj

RPA Automation Anywhere Online Training said...

Great Site, The Course were so simple and easy to understand.
RPA Automation Anywhere Training
RPA Automation Anywhere Online Training

service care said...

Superb.. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing post.
redmi service center
mi service center
redmi service center near me

مروة محمد said...

شركة تسليك مجاري بالدمام



شركة كشف تسرب المياه ببريدة




التخلص من رائحة الحمام بالخبر

spot said...

Nice information keep sharing with us. Please check out web developer also. I hope it will help you.

Unknown said...

agar aapka husband aapse ladai karta hai or aap karna nhi chatey toh aap jarur apne pati ko apne vash main kar sakty ho पति को वश में करने के टोटके kare

al ghadeer said...

شركة تنظيف مكيفات بالرياض
شركة تنظيف مكيفات شمال الرياض
شركة تنظيف مكيفات
شركة تنظيف مكيفات غرب الرياض
شركة تنظيف مكيفات بالخرج
شركة تنظيف مكيفات بالدمام
شركة تنظيف مكيفات بالخبر
فنى صيانة مكيفات سبليت بالرياض
نتيجة الثانوية العامة 2019

_______

Use an image as your UIBarButtonItem

Using an image as your UIBarButtonItem in your navigationcontroller bar can only be achieved by using a common UIButton as the BarButtonItem...