想在用户在屏幕上抽取点上添加一个子。
这里是我方言书中的法典。
- (void)drawRect:(CGRect)rect {
// Drawing code
NSLog(@"drawRect, %i, %i", firstTouch.x, firstTouch.y);
[tagButton drawRect:CGRectMake(firstTouch.x, firstTouch.y, 100, 200)];
[self addSubview:tagButton];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
firstTouch = [touch locationInView:self];
[self setNeedsDisplay];
}
这是从一开始的原样。 律师
2009-10-01 17:27:23.743 文本[2521:207]
如何找到触角的x点和点,并在此问题上建立一个ui子?
感谢任何帮助。
这是人们所看到的,它补充了托邦的观点。 但是,当这种观点消失时。 i 似乎没有发现任何问题。 谁看问题是什么?
UIButton *newButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[newButton setFrame:CGRectMake(self.firstTouch.x, self.firstTouch.y, width, 17)];
[newButton setTitle:[textField text] forState:UIControlStateNormal];
[newButton setFont:[UIFont boldSystemFontOfSize:12]];
[newButton setShowsTouchWhenHighlighted:YES];
[newButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[newButton setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
[newButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[newButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[newButton setBackgroundColor:[UIColor clearColor]];
UIImage *bgImg = [[UIImage imageNamed:@"button_greyblue.png"] stretchableImageWithLeftCapWidth:15.0 topCapHeight:0.0];
[newButton setBackgroundImage:bgImg forState:UIControlStateNormal];
[self setTagButton:newButton];
[self.view addSubview:tagButton];
[newButton release];