How iOS makes a picture appear as a circular style/set control border size and color

Source: Internet
Author: User
Tags border color

For example, the QQ landing avatar is a circular, but in fact its picture is not a circle, but by the layer to draw from. When it comes to layers, each control has a layer property so that any control can be set to a circle, or elliptical to look at the needs of the project

Uiimageview *imageview = [[Uiimageview alloc]initwithimage:[uiimage imagenamed:@ "Avatar. png"];    Imageview.frame = CGRectMake (+, +, +);    Set the corner radius of the control through the layer layers (each control will have a layer level all other controls can also achieve a circular effect)    ImageView.layer.cornerRadius =;    At the same time also to set the outside part of the display so that you can reach a circular slice-    imageview.clipstobounds = YES;        [Mainview.view Addsubview:imageview];

Take a look at the layer also with what properties, you can set what effect, one can set the border size and color of the control, and sometimes it is convenient for us to test the project control is more clear to show the location of the control, such as TableView cell After setting, you can clearly see the size range of each cell, followed by a click to let the control have a selected effect, the more advanced point is to animate the control through the layer layers drawing

Here is the Apple API

@property CGFloat Cornerradius; Set the corner Radius/* The width of the layer ' s border, inset from the layer bounds. The * border is composited above the layer ' s content and sublayers and * includes the effects of the ' Cornerradius ' proper Ty. Defaults to * zero. Animatable. */@property CGFloat borderWidth; Sets the border width of the control/* The color of the layer ' s border. Defaults to opaque black. Colors * Created from tiled patterns is supported. Animatable.  */@property Cgcolorref bordercolor; Sets the border color of the control/* The opacity of the layer, as a value between zero and one. Defaults * to one. Specifying a value outside the [0,1] range would give undefined * results. Animatable. */@property float opacity; Set the transparency of the control some animations will be used for/* when True, and the layer's opacity property is less than one, the * layer is allowed to composite it The self as a group separate from the ITS * parent. This gives is the correct results when the layer contains * multiple opaque are components, and may reduce performance. * * The default value of the property is ReaD from the Boolean * Uiviewgroupopacity property in the main bundle ' s info.plist.  If no * value is found in the Info.plist the default value was YES for * applications linked against the IOS 7 SDK or later and NO for * applications linked against an earlier SDK. */

Only these two words can be set to complete    imageView.layer.borderWidth = 2;//float type data    imageView.layer.borderColor = [Uicolor Redcolor]. Cgcolor;  Color needs to be cgcolor






How iOS makes a picture appear as a circular style/set control border size and color

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.