I want to chance a UIImageView size without changing the UIImageView Location. This is what i got so far:
Person_1.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
I don't want the x and y to be 0. I want the UIImageView on the same place but bigger. Please help!
If you must do it by way of changing the frame, then it would look something like:
Person_1.frame = CGRect(x: Person_1.frame.origin.x, y: Person_1.frame.origin.y, width: 200, height: 200)
Is there a reason you wouldn't be doing it by way of constraints/AutoLayout?
Related
I have a text view and I am attempting to add a line underneath it. I am trying to accomplish this with a CALayer, however it is not showing up in the textView. I would appreciate it if someone could help me. The code is below.
let border = CALayer()
border.backgroundColor = UIColor(hexString: "#CC0000").cgColor
border.frame = CGRect(x: 0, y: messageField.frame.height - 3, width: messageField.frame.width, height: 3)
messageField.layer.addSublayer(border)
In my test app, I just tried this:
let messageField = UITextView(frame: CGRect(x: 30, y: 40, width: view.frame.width - 60, height: 40))
var border = CALayer()
border.backgroundColor = UIColor.red.cgColor
border.frame = CGRect(x: 0, y: messageField.frame.height - 3, width: messageField.frame.width, height: 3)
messageField.layer.addSublayer(border)
view.addSubview(messageField)
And it worked fine. Weird but fine. The color showed up no problem, but it scrolls along with the text view. But that might be what you want. I tried it with different heights for the message field too. I couldn't get it to not show.
If you want it to work and have the line not scroll with the text, try this answer: https://stackoverflow.com/a/38327895/793607
Within a view controller, I have a UIView (backgroundCircle) and a UILabel. The UILabel is moving based on motionManager.startAccelerometerUpdates data. Using this data, I am animating the label.center point. However, I want to bound the movement so that it only moves within a circular area around its starting point (as if it was on a leash from the starting point). Is this possible? Sample code below if it helps.
//objects called during set up
let backgroundCircle = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
backgroundCircle.layer.cornerRadius = circle.frame.width / 2
backgroundCircle.backgroundColor = .clear
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
label.text = "Hello"
//this is called in a separate function, continuously
label.center = newCenter
I'd try using UIKit Dynamics, especially UICollisionBehavior which allows to define collision boundaries with bezier paths.
so I have a table view which is the right size of my screen but the height is wrong because I cann't scroll down to see more parts/cells.
I have set the height in this code:
tableView.frame = CGRect(x: 0, y: 75, width: self.view.frame.width, height: self.view.frame.height)
should I just make the height a really big number or is there a way so that when more cells are filled I can scroll down?
tableView.frame = CGRect(x: 0, y: 75, width: self.view.frame.width, height: self.view.frame.height - 75)
You have add y position at 75. so remove 75 from screen height.
Something like this:
Or follow this link if you can:
https://www.lottiefiles.com/450-play-fill-loader
My case is simpler - I have a view with mask which consists of multiple rects and a linear fill. Mask is created in runtime (so I can't use lottie) but remains permanent, fill is animated (filling from right to left). But how to draw it?
Note: I tried to find a similar animation implementation but in most cases they just try to change the mask params while in my case mask is constant.
If i understand you correct, you can add subview under your mask and change its width, something like that:
let fillingStartFrame = CGRect.init(x: 0, y: 0, width: 0, height: view.frame.height)
let fillingEndFrame = CGRect.init(x: 0, y: 0, width: view.frame.width, height: view.frame.width)
let fillingView = UIView(frame: fillingStartFrame)
view.insertSubview(fillingView, belowSubview: YOUR_MASK)
UIView.animate(withDuration: 0.3) {
fillingView.frame = fillingEndFrame
}
I've created a UIProgressView:
ProgressBar.frame = CGRect(x: 0, y: 0, width: width, height: height)
ProgressBar.center = ProgressPos
ProgressBar.trackImage = UIImage(named: "Ak")
ProgressBar.progress = 0.5
ProgressBar.transform = CGAffineTransformScale(ProgressBar.transform, 1, scale)
self.view?.addSubview(ProgressBar)
Now what I'm trying to do is, let say the progress bar is at 20%, then I want to show the first 20% of that image, I'll try to describe it with a picture:
But it isn't working, I'm not sure what code to use for that, can anybody help me out here?