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.
Related
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
I am trying to set the backgroundImage of a UIButton to an image that could be any size. The way I want to display tall images is for the images to expand to fill the button horizontally, and only show the top part of the image. So for a button with dimensions 100x200 and an image of 80x400, I want to scale the image to 100x500 and only show the top 200 pixels of that scaled image.
I am wondering if there is some way to alter how the background image fills the uibutton (right now it would not preserve the aspect ratio of the image). I tried setting the contentMode of the button and the button's imageView (note I set the button to a Custom Type, not System) to .ScaleAspectFill but that did not do anything.
The closest I came was by ditching the background image entirely and using setImage instead. This code was able to fill the button horizontally, but it shows the middle of the image, not the top. It also had odd functionality where if the scaled image was the same height as the button, it was not showing the full image (about 5 px were cut from the bottom and top). Here is that code:
imagesButton.imageView?.contentMode = .ScaleAspectFill
imagesButton.contentHorizontalAlignment = .Fill
imagesButton.setImage(image, forState: .Normal)
I have looked at about 5 stack overflow posts regarding image resizing in UIButtons, but I can't find the right set of settings that solve my particular need.
I don't know if this solution is an option for you, but the best way to achieve what you're trying to do, and give you pretty as much flexibility as you'd like with positioning and scaling the image, it to use a UIImageView (maybe even with a UIView that wraps it, for more image processing options) with a transparent custom button on top of it.
The upside to this approach is that you'll be able to do pretty much anything you want with the image and the way you display it. The downside is that you lose some of the default UIButton features (such as automatically altering the image when touched). But you can achieve these features programmatically if you want.
I have some very simple UITableViewCells, there is just one one-line UILabel and UIImageView (white arrow). UILabel is anchored to it's parent (content view) top/bottom, the arrow is irrelevant now. When I try to set background view to UIImageView that is loading stretchable image from xcassets, this image view hugs the label which is sizeToFit'ed automatically for some reason.
I have set constraints on both label and background view to anchor them to top/bottom of content view, but they still get small.
The cell's height is 50pt, the label is about 20pt so the difference is quite visible.
Any idea what should I do to have background view fill entire content view?
EDIT:
In following image, you can see 2 cells, one of them in selected state. The bottom cell has both background view and selected background view set. Background view (black one) has no vertical slicing, it's simply image with 50pt height, the Selected background view (the red one) has slicing enabled and it hugs the label vertically.
What I want to achieve is to have slicing enabled for both background and selected background view and having it behave like the non-sliced background view on the image, that is filling entire content view of the cell
EDIT 2:
screenshot of cell layout and constraints set on the imageview that is set as background view on cell
I found related question with answer that helped, so this might be a duplicate.
UITableView - SelectedBackgroundView not working in iOS7 with Auto-Layout
Solution is to create those background view programatically as there is probably yet another bug in interface builder that is screwing this up.
I have a pretty simple scroll view (code below) which i have a picture on
self.detailViewController.scroll.contentSize=CGSizeMake(320, 1200);
self.detailViewController.scroll.showsHorizontalScrollIndicator=YES;
However when i "Scroll to the extreme button or extreme top of the picture or extreme button of the "scroll view, it loops and shows the top of the picture or loops back to the buttom of the picture.
I was wondering if there was some sort of "no repeat" i could set so it shows "black" instead of back to the top of the picture.
Thank you.
colorWithPatternImage tiles the image that it is given. So setting it as the background colour will always result in 'wrap around' if the scroll view can be scrolled outside the edges of the tile image.
To prevent this, choose one of:
Set the content size to the size of the tile image and turn off bouncing
Don't use colorWithPatternImage, use a UIImageView added as a subview of the scroll view.
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.