May I know how can I change the checkbox border colour of UITableViewCell?
You can try adding tint colour to the check mark image before assigning the image to the image view.
let borderImage = self.image?.withRenderingMode(.alwaysTemplate)
self.image = templateImage
self.tintColor = newValue
You can also add it through storyboard by selecting the image view and adding tint color to it.
Related
I have this png image.
How can I change this blue color (only) to a different color in swift.
This because I might need to change to many different colors.
Even better if its possible to change the black color to white.
you can try like this:
self.img.image = self.img.image?.withRenderingMode(.alwaysTemplate)
self.img.tintColor = UIColor.black
let tableImage: UIImageView = {
let image = UIImageView()
image.image = image.withRenderingMode(.alwaysTemplate)
image.tintColor = .white
return image
}()
try this, this will change your image tintColor. I don't think you can set mutiple colors in image
Button image icon tint color changing on click in iOS.
Here is the image of what is happening.
Problem: the color is the default one, not the custom color I have set.
Question: how to set a custom tint color for that button?
Try this one :
if let btnImg = yourBtnOutlet.imageView?.image {
yourBtnOutlet.setImage(btnImg.withRenderingMode(.alwaysTemplate), for: .normal)
yourBtnOutlet.tintColor = UIColor.red
}
I would like to change the background color of the title (only!) in UIButton, which contains title and image.
I can only see how to change to background color of the whole button, which is not what I want.
Any idea ?
You need to set background color of titleLabel:
btn.titleLabel?.backgroundColor = UIColor.red
The full answer is :
btn.tintColor = UIColor.clear //if we have different tint, which I had
btn.titleLabel?.backgroundColor = UIColor.clear
To change button title color:
btn.setTitleColor(UIColor.yourColor, for: .normal)
I am trying for add image as background of UITextview
textView.backgroundColor = UIColor(patternImage: UIImage(named: "Background")!)
Output is :-
Textview not display single image ?
You need to set image in layer of textView instead of setting backgroundColor with UIColor(patternImage:). So set image this way.
textView.layer.contents = UIImage(named: "Background")!.cgImage
With iOS 7, it's now pretty easy to add a blur to UINavigationBar, even with a BarTint, see http://blog.ashleynh.me/frosted-uinavigationbar/ and this example image:
However, there's a border at the bottom. How can I get rid of the border to look more like this?
UPDATE:
I took Danny and Shali's code, and here are the results. As you can see, the border doesn't show any more but there is no blur.
let navigationBarAppearance = UINavigationBar.appearance()
navigationBarAppearance.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navigationBarAppearance.shadowImage = UIImage()
navigationBarAppearance.translucent = true
and here's the Inspector screenshot:
I also tried:
let navigationBarAppearance = UINavigationBar.appearance()
let clearImage = UIImage.imageWithColor(UIColor.clearColor())
navigationBarAppearance.setBackgroundImage(clearImage, forBarMetrics: UIBarMetrics.Default)
navigationBarAppearance.shadowImage = clearImage
navigationBarAppearance.translucent = true
Same result, but the Inspector is a little different:
Apple Documents: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UINavigationBar_Class/index.html#//apple_ref/occ/instp/UINavigationBar/shadowImage
The default value is nil, which corresponds to the default shadow
image. When non-nil, this property represents a custom shadow image to
show instead of the default. For a custom shadow image to be shown, a
custom background image must also be set with the
setBackgroundImage:forBarMetrics: method. If the default background
image is used, then the default shadow image will be used regardless
of the value of this property.
So basically you need to set background image before setting shadowImage to make it work.
Edit
Image generated from color (Swift) as background Navigation. Not sure if your blur function will still work when you change backgroundImage for Navigation bar. That would be a different problem.
class func imageWithColor(color: UIColor) -> UIImage {
let rect = CGRectMake(0, 0, 1, 1)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
color.setFill()
UIRectFill(rect)
var image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
Have you tried navigationBar.shadowImage = [UIImage new]; ?