I have a custom UITableViewCell with a background ImageView. Here is the view hierarchy. The imageView I'm talking about is highlighted in orange.
My problem is that the image is perfect in storyboard (strictly equal to original) but is a little whiter in simulator and on real iPhone when I run the app.
So far :
I checked all tint colors and alphas in the view hierarchy.
I used this code too :
override func awakeFromNib() {
super.awakeFromNib()
backgroundImageView.image = UIImage(named: "Cell Background")?.imageWithRenderingMode(.AlwaysOriginal)
print(backgroundImageView.highlighted)
}
For now I cannot seem to find why there is this little (but design killing) difference between original image and rendered image.
Interesting problem ! The issue was with the slicing of the images actually.
Automatic slicing went a bit too far and so the images didn't not take the center color into account but the shadow at both ends
Related
I know that there is another question with the same title, but none of them worked - especially this Question should solve the problem, but it is not. I set in Assets.xcassets, Render as 'Template Image' and tried to use awakeFromNib() or tintColorDidChange() in a subclass of UITableViewCell, even tried to use a white image with transparent background, but nothing works.
Original question: the tint color feature for an UIImageView inside of a UITableViewCell (with xib file) doesn't work. How to solve it? I use Xcode 10.1 and depolyment target is iOS 10 using Swift 4.2
In my app I have table view cell that is sized at 600x300, and I want to put a background image in each cell that takes up the entire space. I thought I could just throw a 600x300px image into it and it would look fine but the images don't look the best.
So I was wondering how if there were some calculation I could use to find the best image resolution for a TableViewCell, that I could apply to my situation. Thanks!
P.s. I am building my app for the iPhone 6s and 6s Plus.
Here is a picture of the issue, notice how the picture of Hillary Clinton looks weird.
Maybe just set the .ScaleAspectFill property for your image could works.
You can do it in the Storyboard (Attributes inspector, View -> Mode) or by adding the following line :
imgView.contentMode = .ScaleAspectFill
Hope that help you.
So I have a PFQueryTableViewController where date is populated to it from Parse. I have a separate CustomTableViewCell.swift file which manages my cell layout.
The table displays lists of films, along with an poster image for that film. The image is declared as:
#IBOutlet weak var cellFilmImage: PFImageView!
in the CustomTableViewCell.swift file.
I have set constraints to the image in storyboard, for the image to be 95x140:
And I've also set the view mode to be Aspect fill:
I've added a border to my ImageView - which is light gray.
Issue: If I put a larger image there, it doesn't really respond to the settings that I've told it. See a screenshot below of what happens when I set the image to be larger:
You can see the gray outline of the ImageView, but why does the Image not sit inside the view?
Thanks in advance, let me know if you need to see any more of my code/settings.
Looks like you didn't set your imageView.clipsToBounds = true
Or set it from attributes inspector -> check Clip Subviews (Bottom of the image :] )
I am working on a swift app right now, that uses a table view to display news. For the background I set an image using the following line of code in the viewDidLoad method.
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "backgroundImage.jpg")!)
however this makes the background repeat itself when scrolling down, which makes it look very ugly (see attached image).
So what I desire is to have a fixed (non-repetitive) background image that always looks the same while scrolling and does not move at all.
How can I achieve that?
Thank you for your help!
So I did some more digging and finally came across this post: https://stackoverflow.com/a/27684597/2204207
There it suggested to use
self.tableView.backgroundView = UIImageView(image: UIImage(named: "backgroundImage.png"))
instead of
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "backgroundImage.png")!)
Therefore, when you want a fixed and non-repetitive background image use .tableView.backgroundView. This fixes the background images even when scrolling down.
You can make a view hierarchy like this.
Make ImageView and TableView as same size and place table view below the ImageView in view navigator.
Then add your background image to the ImageView and make TableView's background to clear color.
May be the question is elementary, but I have a bug with setBackgroundColor.
I have the UIView which contain UITableView. UITableView is clearColored. I'm trying to set background on UIView:
[self.viewForTable setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:#"bgIngrList.png"]]];
On normal iPad it's looks like:
But on retina iPad (like the second image began showing):
I have two images "bgIngrList.png" and "bgIngrList#2x.png" with 290x260 and 580x520.
Where can be the bug?
EDIT
I have solved the problem by using UIImageView instead of UIView.
Thanks to everybody!!!
colorWithPatternImage: (as the name suggests) thinks your image as pattern to fill. so if the image you give is smaller than the size of the view, its gonna draw the pattern image again rather than stretching it. that is what happening here. your image's size is smaller than view's size hence its drawing the image again at the bottom. You can avoid this by adding a UIImageView and setting the image property rather than setting the backgroundColor of UIView.