mbm*_*414 0 iphone sdk objective-c ios
我想UIView在屏幕上放置一些"手柄" .
所以,我正在创建更多的UIViews,在UIView框架矩形的每个角落都有一个,我只想绘制一个"填充"矩形的圆圈,这个矩形是"手柄"的框架UIView.
这就是我的意思:
我如何创建"HandleView":
CGPoint upperLeft = CGPointMake([[self viewToMove] frame].origin.x - 5, [[self viewToMove] frame].origin.y - 5);
HandleView *uL = [[HandleView alloc] initWithFrame:CGRectMake(upperLeft.x, upperLeft.y, 10, 10)];
[self setUpperLeftHandle:uL];
[uL release];
[[self view] addSubview:[self upperLeftHandle]];
Run Code Online (Sandbox Code Playgroud)
drawRect:for HandleView:
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor orangeColor] set];
CGContextFillEllipseInRect(context, [self frame]);
}
Run Code Online (Sandbox Code Playgroud)
我得到的只是一组黑色矩形,我放置了HandleViews.我不确定为什么它们是黑色的,但我可以通过改变[HandleView backgroundColor]属性来改变颜色.不过,我不能在这个观点上得到任何东西.呼叫setNeedsDisplay似乎没有任何区别.
此外,drawRect:调用方法IS,因此那里的代码存在问题,可能不在其他任何地方.
我已经有一段时间了,因为我搞定了自定义绘图,但我不记得这很难.
我错过了什么?
谢谢!!!
更新:
修改后的代码:
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
[self setBackgroundColor:[UIColor clearColor]];
}
return self;
}
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 100, 100, 100, 1.0);
CGContextFillEllipseInRect(context, rect);
}
Run Code Online (Sandbox Code Playgroud)
现在,我看到了圆圈,但只是在它覆盖另一个视图的地方.它只是坐在"背景"UIView的顶部,我什么都看不到.此外,即使颜色为(100,100,100),它也会显示白色/浅灰色.
这是怎么回事?
这可能有效:
- (void)drawRect:(CGRect)rect {
// Drawing code
[[UIColor orangeColor] setFill];
[[UIBezierPath bezierPathWithOvalInRect:rect] fill];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3642 次 |
| 最近记录: |