iPhone - Image not align at center on UIButton - ios

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.

Related

Button with image and title [duplicate]

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.

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

How to make an NSTextAttachment(image) takes whole line? iOS

In my UITextView, i just set NSMutableAttributeString an NSTextAttachment which is a UIImage. Though i have set the attachment width to the screen width,but when i tap the image, the input cursor will come into the right of my image.
but which i want is:
when insert an image via NSTextAttachment,there should be empty lines at the top and bottom of the image respectively,and the input cursor can only appear in the bottom or the top of the image rather than the left or right.

Custom UITabBar with vertically aligned images

Is there a way to make a the UITabBar show just images that fill the entire TabBarItem?
I tried simply placing an image and deleting the text in the item's title but the image always appears off-center (the area where the title text was remains and I can't align the image to be over it)
Change image inset of UITabBarItem in UITabBar. You could adjust the image inset to make image bigger, smaller, shift to right etc.

Add padding to left margin of UITextField in swift

I have a UITextField with a background image set. The background image consists of a border with an icon on the left side. I'd like to move the cursor so the editing starts after the icon appears. How would I accomplish this in swift?
edit: Would it be easier have a custom border as an uimageview and the textfield placed over it and attached to it? If so what would be the best way to do this?
if you want left padding in TextField just use below code ,
youTextFiled.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
The amount of left padding you can change by changing the value of at first argument .

Resources