Button with image and title [duplicate] - ios

This question already has answers here:
Label under image in UIButton
(35 answers)
Closed 4 years ago.
Anyone have idea how make button on Xcode like on picture(Right side on image)? I want put icon image and title on view container for better alignment like on left side image. But I dont know how get #IBAction property, if it's not be a button.
Image size of my button should be 44x44(green rectangle).
Label(system, 14 pt) should be on frame with size 66x20(if text greater, text should be truncated).
I've tried add to storyboard button and then set background image, title and adjust insets on Size Inspector. Nothing succeeded.
Thanks for help.

You use MTCompoundButton lib.
Link of MTCompoundButton :- https://github.com/mta452/UIView-TouchHighlighting
Now you get UIView and inside of it take UIImage and UILabel.
Then set MTCompoundButton in UIView.

My advice would be to simply use a UIImage and then have a UIButton above that image with no text inside of it. All of this can be done within the storyboard. Just make sure that the button is the same size of the image, is transparent, and does not have any text within it. You can then link the button to your ViewController and use the #IBAction function.

Related

Xcode Button image top text below in a button not in code

I create a button set image title like below picture.
I want
image
title
image on the top title below is it possible without any code?
I cant just use insets because to another size will wrong
Adjust both the title insets and the image insets.
It will need some calculations, and auto layout will probably screw it up ;)
Probably better to create a subclass of UIButton with a .xib
click the link to view my screenshot

Center UIButton with image next to it

I'm trying to create a UIButton where the facebook icon is a part of the centering, however i can't seem to figure out how to make it part of the centering process. So far i've just created a UIButton with the text. I could just create a image next to it, however then it will not be part of the centering.
You can easily set image and title both for your button for different control state like normal,selected or highlighted etc.
So, set your image and title to your button from storyboard or programmatically there is no need to take separate imageview for image.
You can set edge insets for title and image both from interface builder or programmatically. you can manage top or bottom edge insets for title and image of button to manage it's vertical appearance!
check screen shot below,
Update : (as asked in comment)
For example,
this is the setup for my back button with image!
Provide button title and image for normal state. Then just change the left inset for image as per image

In Swift, how to customize the more menu on a tab bar?

I'm trying to change the back ground and size of the cells but on the more menu but am not sure how to do so. Here is what it looks like now:
I want to add a ui image as a backgrounds as well as add a ui image as a background to each cell so it will look like this:
I saw an old post about this on Stack Overflow but it was 7 years old. Does anyone know how to change the more menu in Swift?
In storyboard
1) add a uiImageView to the ViewControll or TableViewControll that you are using. set Constraint UImageView to SuperView as equal width,equal length,central horizontally and central vertically.
set outlet to access.
2) set tableview background to clear colour in attribute property
3)in tableview cell add a UIImageView and set the same equal width, length ,central horizontal and central vertical to contentView.
cell.background colour should be clear .
based on tab you should change the background image in tableview cell imageView in cellforIndexMethod.
you can change the background image of mainBackground in viewDidLoad or viewDidAppear based on the tab

How do you display an exact size button using IB?

I've got a button created in photoshop which is already the exact size to use for displaying.
In IB I created a RRB and set the background image to the button .png. However this doesn't display properly - there is a white boarder between my .png button and the button provided by IB, especially at the corners which must have a different radius. I've tried playing with all the various setting in IB but couldn't get it to go away.
However if instead of setting the .png to the background image I set it to the image then it looks perfect (what is the difference between the image and the background image?).
However I simply cannot get the button text to appear when the .png is set to the image as opposed to the background, though it does when the .png is set to the background image. Again I've tried setting all various settings in IB but cannot get the text to appear.
WHat am I doing wrong, what should I be doing to get it to work?
I know I could create the button and text programatically, but I want to understand why I can get it to work using IB.
EDIT:
I've changed the type to custom but it still doesn't appear properly. See the images I've posted, the one without the text is how it should appear and what it looks like if I set the .png to the image rather than the background. The second one is what it looks like if I set the background image to the .png and set the type of button to custom. THe 3rd one is the background image set to the .png and the type as rounded rect.
Use button type = UIButtonTypeCustom
It looks like your button background image doesn't have the same dimensions as your UIButton.
iOS supports something called "strechable images", allowing you to define which part of the image should be streched. Unfortunately, this can't be done in Interface Builder. In code, you can do it like this:
-(void)viewDidLoad
{
[super viewDidLoad];
UIImage *stretchableImage = [[someButton backgroundImageForState:UIControlStateNormal] stretchableImageWithLeftCapWidth:5 topCapHeight:5];
[someButton setBackgroundImage:stretchableImage forState:UIControlStateNormal];
}
IMPORTANT: stretchableImageWithLeftCapWidth:topCapHeight: is deprecated in iOS 5, but the only solution if you need to support iOS 4 as well. If you can go iOS 5 only, use resizableImageWithCapInsets:.
Rather than using a Rounded Rectangle button type, set the button type to UIButtonTypeCustom.
This will do as you want, in that it will wrap the button around the image you provide it.

iPhone - Image not align at center on UIButton

I have customized UIButton with the following properties:
84x44 frame
84x44 background image
32*32 image that should be centered
but my image is always aligned to the left. How can I align it back to center position on the UIButton?
I have a title on my button that is hidden (clearColor). These titles are key_value in a dictionary so I know which button is pressed and return corresponding value in the dictionary.
I now understand that it's these text that is pushing my image sideway, but how do I fix that?
Under attribute inspector,
there is a tap named Edge, set to Image.
I set left value as 22
and all image align to center.
Can someone explain to me how this works?
Check that your titleLabel is blank - if it has text, it will push the image to the left to make room for the titleLabel on the right.

Resources