วันอังคารที่ 5 มีนาคม พ.ศ. 2556

Add UIView Slider Down


lbView.backgroundColor = [UIColor blackColor];
    lbView.frame = CGRectMake(0, 0, 320, 480);
    lbView.alpha = 0.7;
    UIButton *removeLbView = [UIButton buttonWithType:UIButtonTypeCustom];
    removeLbView.frame = CGRectMake(0, 0, 320, 480);
    [removeLbView addTarget:self action:@selector(removeShareLocationTapped) forControlEvents:UIControlEventTouchUpInside];
    [lbView addSubview:removeLbView];
    [self.view addSubview:lbView];
    self.myLocationView.frame = CGRectMake(0, -400, 320, 480);
    [self.view addSubview:self.myLocationView];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    self.myLocationView.frame = CGRectMake(0, 0, 320, 400);
    [UIView commitAnimations];


- (void)removeShareLocationTapped {
    [lbView removeFromSuperview];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    self.myLocationView.frame = CGRectMake(0, -400, 320, 400);
    [UIView commitAnimations];

    
}

iOS UITableView Tutorial

.h

@property (retain, nonatomic) NSArray *tableData;

.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Initialize table data
    self.tableData = [NSArray arrayWithObjects:@"Egg Benedict"@"Mushroom Risotto"@"Full Breakfast"@"Hamburger"@"Ham and Egg Sandwich"@"Creme Brelee"@"White Chocolate Donut"@"Starbucks Coffee"@"Vegetable Curry"@"Instant Noodle with Egg"@"Noodle with BBQ Pork"@"Japanese Noodle with Pork"@"Green Tea"@"Thai Shrimp Cake"@"Angry Birds Cake"@"Ham and Cheese Panini"nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.tableData count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row];
    return cell;
}

วันเสาร์ที่ 2 มีนาคม พ.ศ. 2556

iOS formatted String For Duration


- (NSString*)formattedStringForDuration:(NSTimeInterval)duration
{
    NSInteger minutes = floor(duration/60);
    NSInteger seconds = round(duration - minutes * 60);
    return [NSString stringWithFormat:@"%d:%02d", minutes, seconds];
}

- (NSString *)stringFromTimeInterval:(NSTimeInterval)interval {
    NSInteger ti = (NSInteger)interval;
    NSInteger seconds = ti % 60;
    NSInteger minutes = (ti / 60) % 60;
    NSInteger hours = (ti / 3600);
    return [NSString stringWithFormat:@"%02i:%02i:%02i", hours, minutes, seconds];
}

วันศุกร์ที่ 1 มีนาคม พ.ศ. 2556

iOS animation uibutton images


myButton.imageView.animationImages =
[NSArray arrayWithObjects:[UIImage imageNamed:@"image1.png"],
                          [UIImage imageNamed:@"image2.png"],
                          nil];
myButton.imageView.animationDuration = 0.5; //whatever you want (in seconds)
[myButton.imageView startAnimating];

UIView beginAnimations Finished


[UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
    self.view.frame = CGRectMake(x,y,width,height);
    [UIView commitAnimations];

-(void)animationFinished:(NSString *)animationID
                finished:(NSNumber *)finished
                 context:(void *)context
{
 NSLog(@"Animation Finished");
}

iOS Resize Image scaled To Width


// Function
- (UIImage*)imageWithImage: (UIImage*) sourceImage scaledToWidth: (float) i_width
{
    float oldWidth = sourceImage.size.width;
    float scaleFactor = i_width / oldWidth;
    
    float newHeight = sourceImage.size.height * scaleFactor;
    float newWidth = oldWidth * scaleFactor;
    
    UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight));
    [sourceImage drawInRect:CGRectMake(0, 0, newWidth, newHeight)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}


Use : [self imageWithImage:image scaledToWidth:254];

UIImageView Scaling in an Image