It might be the stupidest question you saw all day but i couldn't find a solution. i have a rounded image view with borders and i want the borders to be the the same blue as the default tint color in Xcode so if you could help that would be great . and sorry for the noonish question ;)
Now i have this:
self.imageView.layer.borderColor = UIColor.gray.cgColor
and i need to change
UIColor.gray.cgColor
to be the same blue as the default tint color without causing a crash or an error ... how can it be done?
thanks for your help.
just create the new color with blue color properties and apply to imageView
let color = UIColor(colorLiteralRed: 0, green: 122/255, blue: 1, alpha: 1.0)
self.imageView.layer.borderColor = color.cgColor
alertnatively you can use tintColor property of imageView like
imageView.layer.borderColor = imageView.tintColor.cgColor
Just drag and drop whatever color you want such as:
Related
How to set profile Border opacity ?
How to set transparent for having opacity of border color with .white of 50% opacity.
profileView.layer.borderWidth = 3.0
profileView.layer.borderColor = UIColor.white.cgColor
Use withAlphaComponent:
profileView.layer.borderColor = UIColor.white.withAlphaComponent(0.5).cgColor
or:
profileView.layer.borderColor = UIColor.white.cgColor.copy(alpha: 0.5)
Obviously you can choose whatever alpha value you want in the range 0.0 to 1.0.
Or in this case you can use:
profileView.layer.borderColor = UIColor(white: 1.0, alpha: 0.5).cgColor
for alternative you can add UIView behind and set it as border of you ImageView, it's easier to set the oppacity
I have created a UI Picker but the default is just it being transparent. I would like to use/be given the RGB + translucency values that makes the grey color that is commonly used on picker views.
It is the same grey like the defualt color for a programmatic UI Date Picker. Thank you! I need this to be in alignment with Apple's Human Interface Guidelines.
Added a picture of the background color/translucency I need below:
iPhone SDK has two types of gray color both have opacity 1.
iOS 13 also introduces a range of six opaque gray colors you can use in rare cases where translucency doesn't work well.
https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/
And for changing the background color.
light gray color:
picker.backgroundColor = UIColor.lightGray
dark gray color:
picker.backgroundColor = UIColor.darkGray
if you want some transparency on the picker view. You can add Gradient on it.
let view = UIView(frame: CGRect(x: 0, y: 0, width: picker.frame.width, height: picker.frame.height))
let gradient = CAGradientLayer()
gradient.frame = view.bounds
gradient.colors = [UIColor.white.cgColor, UIColor.lightGray.cgColor]
picker.layer.insertSublayer(gradient, at: 0)
find the image as it looks with gradient and light gray color.
picker view with gradient
Hex color - #e8e9ed
RGB color - UIColor(red: 232/255, green: 233/255, blue: 237/255, alpha: 1)
or you can use #f7f7f7
I hope it works.
I made a custom view and I called it in UINavigationController, I made it transparent but after I put it inside navigation controller I got that border, how to remove it?
thanks in advance
Try to set border width of your view with 0
yourView.layer.borderWidth = 0
You need to set the border color of your view transparent.
yourview.layer.borderColor = UIColor.clearColor()
This should work.
Update on Swift 3+
yourview.layer.borderColor = UIColor.clear.cgColor
Try this code out. (91,158,236) is the color of your navigation bar.
yourview.layer.borderColor = UIColor(red: 91.0 / 255, green: 158.0 / 255, blue: 236.0 / 255, alpha: 1.0).CGColor
For a red View contained in navigation Bar for a borderWidth of 4.0 it would produce result like
Hope this helps.
I try to change the headerView's border color to surfing green, but it seems that my code does not work. What I tried is this:
tableView.tableHeaderView?.layer.borderColor = UIColor(red: 105.0/255.0, green: 215.0/255.0, blue: 189.0/255.0, alpha: 1.0).CGColor
tableView.tableHeaderView?.layer.masksToBounds = true
However, the header's border still looks like this:
Here is the Image (Sorry I do not have enough reputation to post images)
As you can see, the border is still black/deep blue.
Any help would be greatly appreciated! Thanks in advance!
I think there is problem with border between navigation bar and search bar...
check on this link for solution
searchBar.backgroundImage = UIImage()
some example to change border:
searchBar.layer.borderWidth = 1
searchBar.layer.borderColor = someColor.CGColor
I am trying to add a top and right border to my button but not the bottom or left. I looked it up and found a suggestion to do so by adding views to look like borders.
//Add borders
let topBorder = UIView(frame: CGRectMake(0, 0, editorBox.frame.size.width/3, 1))
let rightBorder = UIView(frame: CGRectMake(cancel.frame.size.width, 0, 1, cancel.frame.size.height))
topBorder.backgroundColor = UIColor(red: 220/255.0, green: 220/255.0, blue: 220/255.0, alpha: 1.0)
rightBorder.backgroundColor = UIColor(red: 220/255.0, green: 220/255.0, blue: 220/255.0, alpha: 1.0)
cancel.addSubview(topBorder)
cancel.addSubview(rightBorder)
But the resulting Simulator test looks like:
However, the button is definitely not that big because you can't click on the far right side of it. The auto layout constraints confirm that the button is not that big.
I just want each button to have a border around it's actual 1/3 width size, as set in the constraints. Can anyone tell me what's happening and how to fix it?
Looks to me to be an autolayout issue - your button is being generated before the layout changes its width. Your border views, on the other hand, do not get their width changed because they're outside of the constraint hierarchy.
For something this simple though, I think UIViews are a bit too much. I would add a few CALayers to the Button in question.
Here's a stack overflow question directly relating to the CALayer solution:
CALayer: add a border only at one side
It turns out that the other answer didn't solve my border problem by itself. Here's the code I'm using, based on the #tbondwilkinson answer:
//Add borders
let borderColor = UIColor(red: 200/255.0, green: 200/255.0, blue: 200/255.0, alpha: 1.0).CGColor
func formatTopBorder (buttonToFormat: UIButton,borderToFormat: CALayer) {
buttonToFormat.clipsToBounds = true
borderToFormat.borderColor = borderColor
borderToFormat.borderWidth = 2
borderToFormat.frame = CGRectMake(0, 0, CGRectGetWidth(cancel.frame), 2)
}
let topBorder: CALayer = CALayer()
let topBorder2: CALayer = CALayer()
let topBorder3: CALayer = CALayer()
let rightBorder: CALayer = CALayer()
let leftBorder: CALayer = CALayer()
formatTopBorder(cancel, borderToFormat: topBorder)
formatTopBorder(action, borderToFormat: topBorder2)
formatTopBorder(addSave, borderToFormat: topBorder3)
rightBorder.borderColor = borderColor
rightBorder.borderWidth = 2
rightBorder.frame = CGRectMake(CGRectGetWidth(cancel.frame)-2, 0, 2, CGRectGetHeight(cancel.frame))
leftBorder.borderColor = borderColor
leftBorder.borderWidth = 1
leftBorder.frame = CGRectMake(0, 0, 2, CGRectGetHeight(cancel.frame))
cancel.layer.addSublayer(topBorder)
cancel.layer.addSublayer(rightBorder)
action.layer.addSublayer(topBorder2)
addSave.layer.addSublayer(topBorder3)
addSave.layer.addSublayer(leftBorder)
But if placed in the viewDidLoad, it doesn't work perfectly. The top borders work and so does the left border. However, it was still prematurely getting the UIButton width, resulting in the right border not working:
rightBorder.frame = CGRectMake(CGRectGetWidth(cancel.frame)-2, 0, 2, CGRectGetHeight(cancel.frame))
The CGRectGetWidth(cancel.frame)-2 gets the correct right edge and gives space for the border, but it gets the width before the button has sized itself.
The solution:
Use the method and then put that code in the viewDidAppear. Unfortunately, the borders appear a fraction of a second after your view appears, but all the borders will be correct.
If anyone can post code that works for a right-edge border, that runs in the viewDidLoad, please post it and I'll mark it correct.