简体   繁体   English

像iPhone的主屏幕图标一样绘制项目

[英]Draw an Item like home screen icon of iPhone

I want to draw an Item that similar as item of iPhone. 我想绘制一个类似于iPhone项目的项目。 I have also draw with UIView like this 我也像这样用UIView画画 在此输入图像描述

But the item I want like this : 但我想要的项目如下: 在此输入图像描述

How can I draw like round buttton? 我怎么画像圆形的按钮?

USE THIS CODE 使用此代码

  UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  [bt setFrame:CGRectMake(10, 10, 50, 50)];
  [bt setImage:[UIImage imageNamed:@"abc.png" ] forState:UIControlStateNormal];

  // Get the Layer of any view
  CALayer * l = [bt layer];
  [l setMasksToBounds:YES];
  [l setCornerRadius:10.0];

  // You can even add a border
  [l setBorderWidth:4.0];
  [l setBorderColor:[[UIColor blueColor] CGColor]];
  [self.view addSubview:bt];

Set the corner Radius of your view and insert the label below it. 设置视图的角半径并在其下方插入标签。

iPhone supports the cornerRadius property on the CALayer class. iPhone支持CALayer类的cornerRadius属性。 Every view has a CALayer instance that you can manipulate. 每个视图都有一个可以操作的CALayer实例。

First of all #import <QuartzCore/QuartzCore.h> and link to the QuartzCore framework to get access to CALayer's headers and properties.Then, 首先#import <QuartzCore/QuartzCore.h>并链接到QuartzCore framework以访问CALayer的头文件和属性。然后,

yourView.layer.cornerRadius = 8;

你可以做圆边

 yourview.layer.cornerRadius = 8.0; // or other value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM