gpt4 book ai didi

objective-c - drawAtPoint,需要说明

转载 作者:行者123 更新时间:2023-11-28 22:54:43 24 4
gpt4 key购买 nike

我想在屏幕上的某个位置绘制“文本”而不​​使用 UILabel,所以我

[@"text" drawAtPoint:CGPointMake(100, 200) 
withFont:[UIFont fontWithName:@"Arial" size:10.0]];

虽然 drawAtPoint 的描述显示为:

但是什么也没有显示:

Draws the string in a single line at the specified point in the current graphics context using the specified font.

我怀疑,我的错误是我在我的 UIViewController 的 viewDidLoad 方法中调用它,而不是放在 View 上? (但如何?)

同样,使用这种方式并避免使用 UILabel,如何将文本放置在屏幕上的自定义位置?

最佳答案

如果要将字符串绘制到 View ,则需要子类化 View 并实现 drawRect 方法

- (void)drawRect:(CGRect)rect
{
// Drawing code
[[UIColor whiteColor] set];
[@"Your string" drawInRect:CGRectMake(0, 0, 100, 100) withFont:[UIFont systemFontOfSize:16]];
}

not placing onto the view? (But how?)

这是因为字符串将在当前上下文中绘制,当您在 drawRect 中调用它时有效,如果您从 viewDidLoad 调用 [@"Your string"drawInRec... 它不会工作,因为您没有有效的语境

Again, using this way and avoiding the use of UILabel, how can text be placed on screen at custom location?

使用 NSString 来绘制而不是 UILabel,并且您可以使用 drawInRect:withFont

关于objective-c - drawAtPoint,需要说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11064872/

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