Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I do not want to make IBOutlet of the constraint between view and the top layout guide.I do not want to put identifier also. I want to find it programatically.Anyone please help me.
Select the constraint and add the identifier 'TopLayOut' like added in the pic below:
and in your code iterate through the constraints and find the right one as below:
for constraint in self.view.constraints{
if constraint == "TopLayOut"{
print("matches")
break;
}
}
This is how you have to declare the constraint programatically. Please find the code snippet.
let view = UIView()
let leadingConstraint = view.leadingAnchor.constraintEqualToAnchor(self.view.leadingAnchor)
let trailingConstraint = view.trailingAnchor.constraintEqualToAnchor(self.view.trailingAnchor)
let topConstraint = view.topAnchor.constraintEqualToAnchor(self.view.topAnchor)
let bottomConstraint = view.bottomAnchor.constraintEqualToAnchor(self.view.bottomAnchor, constant: 0)
var setConstraints = [NSLayoutConstraint]()
setConstraints.appendContentsOf([leadingConstraint,trailingConstraint,topConstraint,bottomConstraint])
NSLayoutConstraint.activateConstraints(setConstraints)
Please tick If it's helps.
Thanks.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to add a card view to the rows of the section, where for the first row I want the top left and top right shadow with corner radius and the last row of the section will have the bottom left and bottom right shadow with corner radius. So in the middles rows will have only left and right shadow without corner radius.
Try this it is working for me
yourRowView.layer.shadowOpacity = 0.8
yourRowView.layer.shadowOffset = CGSize(width: 0, height: 3)
yourRowView.layer.shadowRadius = 4.0
let shadowRect: CGRect = imageView.bounds.insetBy(dx: 0, dy: 4)
yourRowView.layer.shadowPath = UIBezierPath(rect: shadowRect).cgPath
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a problem: my scroll view scrollable, when content is fully visible. What should i do, to enable scrolling, when some part of content is hidden?
This is the solution. I faced the same issue few months back.
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
ScrollView.contentSize = CGSize(width: self.view.frame.width, height: self.view.frame.height)
ScrollView.isScrollEnabled = true
ScrollView.showsVerticalScrollIndicator = false
}
Enjoy!
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have made a custom attribute inspector for my text field:
#IBInspectable var bottomColor: UIColor = UIColor.clear {
didSet {
if bottomColor == UIColor.clear {
self.borderStyle = .roundedRect
} else {
self.borderStyle = .bezel
}
self.setNeedsDisplay()
}
}
Now I want to set bottomColor to red when the form is submitted with an empty text field. Which would be the best way to do this?
I'm putting my logic here
For do that you need to add bottom border of UITextField
UITextField border for bottom side only in swift OR How to only show bottom border of UITextField in Swift
Then you need to set color of this bottom border that you want
After remove same you need to set 0 width of bottom border of UITextField clear color of border.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to display a picker next to a textfield, when the user starts editig. After editing, the picker disappears.
Therefore I changed the width of a textfield like this in textFieldDidBeginEditing:
func textFieldDidBeginEditing(_ textField: UITextField)
{ print ("textFieldDidBeginEditing")
let newSize = CGSize(width: 90.0, height: textfield.frame.height)
let newFrame = CGRect(origin: textfield.frame.origin, size: newSize)
textfield.frame = newFrame
}
In textFieldDidEndEditing the width is reset to the old value.
This works fine the time (beginEditing, endEditing)
In following attempts the with is not changed again (the print statement is reached)
What´s going wrong.
Everything works fine in my test project, try insert textfield.setNeedsDisplay() after set new frame.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can we put constraints like
The vertical distance between two buttons must be '20 points' in the screen of height '568 points' and
must be '25 points in the screen of height '667 points' ?
I think you want the gap between the buttons dynamic for all device screens. Here is the way you can use to make this happen. i think you don't want to assign exact values for checking all devices every time. Take a UIView with alpha 0 and clear color and use it instead of the gap and use those constraints for the gap view.
1) Vertical spacing 0 between the top button and the gap view.
2) Vertical spacing 0 between the bottom button and the gap view.
3) Equal width to top or bottom button.
4) Center X to top button or bottom button.
5) Proportional Height to main view(you can add this constraint by adding equal height from subview to any of superview and then by changing the multiplier);
And your GapView will increase and decrease accordingly.
First of all get the screen height with this:
var bounds = UIScreen.mainScreen().bounds
var height = bounds.size.height
After that you can set constraint this way with height:
switch height {
case 568:
buttonSpecing.constant = 20
case 667:
buttonSpecing.constant = 25
default:
println("Not Found")
}
And you can create buttonSpecing outlet this way:
Hope this will help.