วันอังคารที่ 19 มีนาคม พ.ศ. 2556
UIScrollView sample
self.scrollView.contentSize = CGSizeMake(self.mainView.frame.size.width, self.mainView.frame.size.height);
[self.scrollView addSubview:self.mainView];
วันจันทร์ที่ 11 มีนาคม พ.ศ. 2556
color with RGBA
- (UIColor *)colorWithRGBA:(NSUInteger)color
{
return [UIColor colorWithRed:((color >> 24) & 0xFF) / 255.0f
green:((color >> 16) & 0xFF) / 255.0f
blue:((color >> 8) & 0xFF) / 255.0f
alpha:1.0f];
}
use : [self colorWithRGBA:041143255];
วันพฤหัสบดีที่ 7 มีนาคม พ.ศ. 2556
iOS Image From UIView
- (UIImage*)imageFromView:(UIView *)view
{
// Create a graphics context with the target size
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
CGSize imageSize = [view bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// -renderInContext: renders in the coordinate space of the layer,
// so we must first apply the layer's geometry to the graphics context
CGContextSaveGState(context);
// Center the context around the view's anchor point
CGContextTranslateCTM(context, [view center].x, [view center].y);
// Apply the view's transform about the anchor point
CGContextConcatCTM(context, [view transform]);
// Offset by the portion of the bounds left of and above the anchor point
CGContextTranslateCTM(context,
-[view bounds].size.width * [[view layer] anchorPoint].x,
-[view bounds].size.height * [[view layer] anchorPoint].y);
// Render the layer hierarchy to the current context
[[view layer] renderInContext:context];
// Restore the context
CGContextRestoreGState(context);
// Retrieve the screenshot image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
วันอังคารที่ 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];
}
{
[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];
}
{
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;
}
{
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];
}
สมัครสมาชิก:
บทความ (Atom)