2/22/2011

Common Object Declerations in XCode

It will be one of the useful post for me.There will be declerations and properties of common objects like buttons or images.

STRING:
Creating URL with string
NSString *customURL=[NSString stringWithFormat:@"%@&categoryID=%i&pageID=%i", VIDEOS_URL, categoryID, pageID];
NSURL *url = [NSURL URLWithString:customURL];

IMAGES:
UIImageView *image=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageWidth, imageHeight)];
[image setContentMode:UIViewContentModeScaleToFill];
[image setImageWithURL:
[NSURL URLWithString:[tnPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ]
placeholderImage:[UIImage imageNamed:@"place_holder_news_manset.png"]];

LABEL:
UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(0, imageHeight+5, imageWidth, height)];
[label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13]];
[label setAdjustsFontSizeToFitWidth:NO];
[label setShadowOffset:CGSizeMake(0, 0)];
label.numberOfLines=2;
label.backgroundColor=[UIColor yellowColor];
label.text=title;
---------------------------------------------------------------------------------------------------------------------------------------

[footerLabel setFont:[UIFont fontWithName:@"Arial" size:14]];
[footerLabel setFont:[UIFont boldSystemFontOfSize:14]];
footerLabel.backgroundColor = [UIColor clearColor];
[footerLabel setTextAlignment:UITextAlignmentCenter];

BUTTON:
UIButton *dummyButton=[[UIButton buttonWithType:UIButtonTypeCustom] retain];
[dummyButton setFrame:CGRectMake(xPosition, yPosition, imageWidth, SECTION_HEADER_HEIGHT-yPosition)];
[dummyButton addTarget:self action:@selector(clearBackgroundColor:) forControlEvents:UIControlEventTouchDragOutside];
[dummyButton setTag:i];
[dummyButton setAutoresizesSubviews:NO];
[dummyButton setBackgroundColor:[UIColor lightGrayColor]];
---------------------------------------------------------------------------------------------------------------------------------------
UIButton *footerButton = [[UIButton alloc]init];
footerButton = [UIButton buttonWithType:UIButtonTypeCustom];
footerButton.frame =CGRectMake(0, 0, 320, 41);
[footerButton setImage:[UIImage imageNamed:@"footer_back.png"] forState:UIControlStateNormal];
[footerButton setImage:[UIImage imageNamed:@"footer_back_active.png"] forState:UIControlStateHighlighted];


VIEW:
Creating a view object:
- (id)initWithFrame:(CGRect)frame parentVC:(UIViewController *)parentController{
if ((self = [super initWithFrame:frame])) {
parentViewController=parentController;
....
}
return self;
}
Calling view and use it as subview:
topView=[[TopView alloc] initWithFrame:CGRectMake(0, 0, 320, 44) parentVC:self];
[self.view addSubview:topView];

Using subview array:
NSArray* subviews = [NSArray arrayWithArray: topView.subviews];
if (self.navigationController==self.tabBarController.moreNavigationController) {
self.tabBarController.moreNavigationController.navigationBar.hidden=YES;
[delegate changeTopViewsAppearance:NO array:subviews];
[delegate.foreCastView setHidden:YES];
}

ALERTBOX:
-(void)getUserName{
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"İsminizi giriniz:" message:@"this gets covered" delegate:self cancelButtonTitle:@"GİRİŞ" otherButtonTitles:nil, nil];
userName = [[[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]retain];
[userName setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:userName];
[myAlertView show];
[myAlertView release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:userName.text forKey:@"user_preference"];
[self sendUserCoordinates];
NSLog(@"%@",userName.text);
}
else {
NSLog(@"user pressed Cancel");
}
}


No comments:

Post a Comment