Iphone Tutorials
Wednesday, November 21, 2012
Saturday, November 17, 2012
Tuesday, April 10, 2012
How to style UITextview to like Rounded Rect text field?
[yourTextView.layer setBackgroundColor: [[UIColor whiteColor] CGColor]];
[yourTextView.layer setBorderColor: [[UIColor grayColor] CGColor]];
[yourTextView.layer setBorderWidth: 1.0];
[yourTextView.layer setCornerRadius:8.0f];
[yourTextView.layer setMasksToBounds:YES];
Friday, December 9, 2011
iPhone how to check that a string is numeric only
static bool TextIsValidValue( NSString* newText, double &value )
{
bool result = false;
if ( [newText isMatchedByRegex:@"^(?:|0|[1-9]\\d*)(?:\\.\\d*)?$"] ) {
result = true;
value = [newText doubleValue];
}
return result;
}
- (IBAction) doTextChanged:(id)sender;
{
double value;
if ( TextIsValidValue( [i_pause stringValue], value ) ) {
[i_pause setTextColor:[NSColor blackColor]];
// do something with the value
} else {
[i_pause setTextColor:[NSColor redColor]];
}
}
Wednesday, August 10, 2011
Detecting direction of a swipe
Detecting direction of a swipe
MainView.h
Code:
#import
#import
@interface MainView : UIView {
IBOutlet UILabel *whataction;
CGPoint gestureStartPoint;
}
@end
MainView.m
Code:
#import "MainView.h"
@implementation MainView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self];
if (currentPosition.x - 30 > gestureStartPoint.x) {
[whataction setText:@"FAR RIGHT"];
}
else if (currentPosition.x > gestureStartPoint.x) {
[whataction setText:@"RIGHT"];
}
if (currentPosition.x + 30 < gestureStartPoint.x) {
[whataction setText:@"FAR LEFT"];
}
else if (currentPosition.x < gestureStartPoint.x) {
[whataction setText:@"LEFT"];
}
if (currentPosition.y - 30 > gestureStartPoint.y) {
[whataction setText:@"FAR DOWN"];
}
else if (currentPosition.y > gestureStartPoint.y) {
[whataction setText:@"DOWN"];
}
if (currentPosition.y + 30 < gestureStartPoint.y) {
[whataction setText:@"FAR UP"];
}
else if (currentPosition.y < gestureStartPoint.y) {
[whataction setText:@"UP"];
}
}
@end
MainView.h
Code:
#import
#import
@interface MainView : UIView {
IBOutlet UILabel *whataction;
CGPoint gestureStartPoint;
}
@end
MainView.m
Code:
#import "MainView.h"
@implementation MainView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self];
if (currentPosition.x - 30 > gestureStartPoint.x) {
[whataction setText:@"FAR RIGHT"];
}
else if (currentPosition.x > gestureStartPoint.x) {
[whataction setText:@"RIGHT"];
}
if (currentPosition.x + 30 < gestureStartPoint.x) {
[whataction setText:@"FAR LEFT"];
}
else if (currentPosition.x < gestureStartPoint.x) {
[whataction setText:@"LEFT"];
}
if (currentPosition.y - 30 > gestureStartPoint.y) {
[whataction setText:@"FAR DOWN"];
}
else if (currentPosition.y > gestureStartPoint.y) {
[whataction setText:@"DOWN"];
}
if (currentPosition.y + 30 < gestureStartPoint.y) {
[whataction setText:@"FAR UP"];
}
else if (currentPosition.y < gestureStartPoint.y) {
[whataction setText:@"UP"];
}
}
@end
Subscribe to:
Posts (Atom)