我正在寻找一种方法来创建UIView
可调整大小并保持居中的 CIRCULAR(见图)。本例中的 CIRCULAR 视图是一个UIView
子类WCSDailyGoal
。
容器视图.m
- (void)createDailyGoalView
{
_dailyGoalView = [[WCSDailyGoalView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
_dailyGoalView.delegate = self;
_dailyGoalView.goal = 200;
_dailyGoalView.center = self.view.center;
[self.view addSubview:_dailyGoalView];
}
WCSDailyGoal.m
- (void)setGoal:(CGFloat)goal
{
CGPoint saveCenter = self.center;
CGRect newFrame = CGRectMake(self.frame.origin.x, self.frame.origin.y, goal, goal);
self.frame = newFrame;
self.layer.cornerRadius = goal / 2.0;
self.center = saveCenter;
}