Thursday, 15 May 2014

ios - How to set UIImageView in the center of screen horizontally or vertically with Swift, but no more StoryBoard -


I am trying to put UIImageView at the upper center of the horizontal screen which is coding ViewsDidload () and I have two pre-plans, which means that I do not know the function or the API specified.

1). I want to set a variable that is equal to the width of the screen. And I know that this is going to work with something about 'border' or 'frame', parental, I do not know those functions or parameters

2). To confirm the resolution, I have to find out the currentDevice , then I UIImageView to CGRectMake ((resolution.x) / 2, y, length, width ) . Can a function confirm currentDevice ?

And I think the first person is more efficient than the other.

Appreciate your help and guidance.

Ethan J

I would recommend using automatic:

ImageContent (wrong) view.addSubview (imageView) // Create constraints and add them to an array Var constraints = [AnyObject] () // This obligation image Move horizontally to screen obstacles. Append (Anselut contract (item: See image, featuring: Anselaautativetkkentraks, Related: like: Anselaautreleshn. Akwal, Aiaitim: See, attribution: Anselaautativetkkentraks multiplier: 1.0, constant: 0.0)) // now we top the scenes Enter the imageView on the margin. Append (Anslaut content (items: See image, featuring: Anselaut feature. Related: NSLayoutRelationkEqual, ToItem View, featuring: NSLayoutAttributekTopMargin, multiplier: 1.0, constant: 0.0)) // You height of imageView // about must also set some obstacle or it as example featuring imageView, featuring: // of BottomMargin or any other object below is placed right under view it with any items such as // basic idea , I 500 constraints.append (NSLayoutConstraint (item Areas set height NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: Zero, featuring: NSLayoutAttributekNotAnAttribute, multiplier: 1.0, continued: 500.0)) // the next line to fire went obstacles saved array NSLayoutConstraint.activateConstraints ( Odds)

This code focuses the imageView in horizontal every device. I recommend that you are checking the auto layout, this is a good feature.

Here's a good link where you can start with:


No comments:

Post a Comment