У меня есть 8 UIButtons. Теперь я хочу создать линию над этими кнопками.
Я пытался, и я могу провести линию. Пожалуйста, проверьте, что я делаю.
MyDrawingView.h
#import <UIKit/UIKit.h>
@interface MyDrawingView : UIView{
CGPoint fromPoint;
CGPoint toPoint;
UIColor* currentColor;
UIImage *backgroundImage;
}
@property CGPoint fromPoint;
@property CGPoint toPoint;
@property(nonatomic,retain) UIColor* currentColor;
@end
MyDrawingView.m
#import "MyDrawingView.h"
@implementation MyDrawingView
@synthesize fromPoint;
@synthesize toPoint;
@synthesize currentColor;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
backgroundImage = [UIImage imageNamed:@"office.jpeg"];
}
return self;
}
- (void)drawRect:(CGRect)rect {
//CGPoint drawingTargetPoint = CGPointMake(100,0);
//[backgroundImage drawAtPoint:drawingTargetPoint];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context,10);
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
CGContextMoveToPoint(context,fromPoint.x , fromPoint.y);
CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
CGContextStrokePath(context);
}
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touchPoint = [touches anyObject];
fromPoint = [touchPoint locationInView:self];
toPoint = [touchPoint locationInView:self];
[self setNeedsDisplay];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* touch = [touches anyObject];
toPoint=[touch locationInView:self];
[self setNeedsDisplay];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* touch = [touches anyObject];
toPoint = [touch locationInView:self];
[self setNeedsDisplay];
}
Теперь в другом классе я использую 8 кнопок на viewDidLoad
, пожалуйста, проверьте, что я делаю.
-(void)viewDidLoad{
8 UIButtons (8 buttons in one line and 10 pixels gap in X-position after every button)
[self method_Call_drawView];
}
-(void)method_Call_drawView{
v = [[MyDrawingView alloc]initWithFrame:CGRectMake(100,350,400,400)];
v.backgroundColor = [UIColor whiteColor];
[v setNeedsDisplay];
[self.view addSubview:v];
}
.h file
#import <UIKit/UIKit.h>
@class MyDrawingView;
@interface iPad_Level1 : UIViewController{
UIButton *btn1;
UIButton *btn2;
UIButton *btn3;
UIButton *btn4;
UIButton *btn5;
UIButton *btn6;
UIButton *btn7;
UIButton *btn8;
MyDrawingView *v;
}
@property(nonatomic,retain)MyDrawingView *v;
@end
Я могу создать вид и нарисовать линию на виде, но я не могу коснуться UIButtons
и создать линию над ним.
Моя линия увеличивается и уменьшается, где бы я ни нажимал, но я хочу, чтобы эта линия была на моем UIButton
.
пожалуйста, проверьте, что я пытаюсь сделать itunes.apple.com/in/app/word-search-puzzles/id609067187?mt=8, проверьте желтую и синюю линии на кнопках.
Любая идея или предложение будут весьма приветствоваться.