Skip to content

Instantly share code, notes, and snippets.

@bacella
bacella / button.m
Created January 26, 2014 05:09
Movable Button on iOS
- (void)viewDidLoad
{
[super viewDidLoad];
self.btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.btn.frame = CGRectMake(10, 10, 50, 50);
[self.btn setTitle:@"Touch" forState:UIControlStateNormal];
[self.btn addTarget:self action:@selector(dragMoving:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[self.btn addTarget:self action:@selector(dragEnded:withEvent:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
[self.view addSubview:self.btn];