Ios 在矩形图形中输入字母
为了显示加载,我画了三个矩形,但是我想在这些矩形中输入字母,我怎样才能在其中输入字母 我的功能:Ios 在矩形图形中输入字母,ios,xcode,hud,Ios,Xcode,Hud,为了显示加载,我画了三个矩形,但是我想在这些矩形中输入字母,我怎样才能在其中输入字母 我的功能: - (void)configUI { self.backgroundColor = [UIColor clearColor]; UIView *rect1 = [self drawRectAtPosition:CGPointMake(0, 0)]; UIView *rect2 = [self drawRectAtPosition:CGPointMake(20, 0)];
- (void)configUI {
self.backgroundColor = [UIColor clearColor];
UIView *rect1 = [self drawRectAtPosition:CGPointMake(0, 0)];
UIView *rect2 = [self drawRectAtPosition:CGPointMake(20, 0)];
UIView *rect3 = [self drawRectAtPosition:CGPointMake(40, 0)];
[self addSubview:rect1];
[self addSubview:rect2];
[self addSubview:rect3];
[self doAnimateCycleWithRects:@[rect1, rect2, rect3]];
}
我想在
rect1
中插入字母“A”,在rect2
中插入字母“B”,在rect3
中插入字母“C”使用UILabel
而不是UIView
。设置标签文本。(请注意,UILabel
的背景颜色与UIView
类似)要在视图上绘制字符串,需要创建UIView
的子类。在视图控制器中导入此视图,并将上述视图创建为自定义视图的对象
在自定义视图中,有一个视图替代方法-
- (void)drawRect:(CGRect)rect;
这是可以绘制字符串和设置绘图属性的地方
例如:自定义视图类
CustomView.h
#import <UIKit/UIKit.h>
@interface CustomView : UIView
@property (nonatomic, strong) NSString *drawString;
@end
现在,在代码中创建此自定义类的视图对象类型:
- (void)configUI {
self.backgroundColor = [UIColor clearColor];
CustomView *rect1 = [self drawRectAtPosition:CGPointMake(0, 0)];
CustomView *rect2 = [self drawRectAtPosition:CGPointMake(20, 0)];
CustomView *rect3 = [self drawRectAtPosition:CGPointMake(40, 0)];
// This will draw text to view
[rect1 setDrawString:@"A"];
[rect2 setDrawString:@"B"];
[rect3 setDrawString:@"C"];
[rect1 setBackgroundColor:[UIColor whiteColor]];
[rect2 setBackgroundColor:[UIColor whiteColor]];
[rect3 setBackgroundColor:[UIColor whiteColor]];
[self addSubview:rect1];
[self addSubview:rect2];
[self addSubview:rect3];
[self doAnimateCycleWithRects:@[rect1, rect2, rect3]];
}
- (void)configUI {
self.backgroundColor = [UIColor clearColor];
CustomView *rect1 = [self drawRectAtPosition:CGPointMake(0, 0)];
CustomView *rect2 = [self drawRectAtPosition:CGPointMake(20, 0)];
CustomView *rect3 = [self drawRectAtPosition:CGPointMake(40, 0)];
// This will draw text to view
[rect1 setDrawString:@"A"];
[rect2 setDrawString:@"B"];
[rect3 setDrawString:@"C"];
[rect1 setBackgroundColor:[UIColor whiteColor]];
[rect2 setBackgroundColor:[UIColor whiteColor]];
[rect3 setBackgroundColor:[UIColor whiteColor]];
[self addSubview:rect1];
[self addSubview:rect2];
[self addSubview:rect3];
[self doAnimateCycleWithRects:@[rect1, rect2, rect3]];
}