gpt4 book ai didi

iPhone Quartz - 从其他类调用绘图方法

转载 作者:行者123 更新时间:2023-11-29 04:38:05 26 4
gpt4 key购买 nike

我试图从A类调用绘图方法,例如位于B类中的方法,该方法正在被调用,但没有发生绘图。

- (void)drawIt
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);

NSString *string = [NSString stringWithString:@"TEXT"];
[string drawAtPoint:CGPointMake(12, 51) withFont:[UIFont fontWithName:@"Helvetica" size:35.0f]];
}

为什么我可以从其他类调用这个方法?

最佳答案

首先创建类“YourView”,它是 UIView 的子类。编写B类中viewDidLoad方法的分配代码

- (void)viewDidLoad{
YourView *temp = [[YourView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:temp];
}

在 YourView.m 中实现 - (void)drawRect:(CGRect)rect 方法

- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
NSString *string = [NSString stringWithString:@"TEXT"];
[string drawAtPoint:CGPointMake(12, 51) withFont:[UIFont fontWithName:@"Helvetica" size:35.0f]];
}

我想这对你会有帮助。

关于iPhone Quartz - 从其他类调用绘图方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10798188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com