I am trying to show into the header of my UITableViewController a title and under it an image illustrating the title. The next code (written into the viewDidLoad method) shows only the image, and this image over the rest of the table sections. How I can fix it to do what I want?
// Creates a header view.
UIView *containerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 60)] autorelease];
UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 40)] autorelease];
headerLabel.text = self.name;
headerLabel.textColor = [UIColor blackColor];
headerLabel.font = [UIFont boldSystemFontOfSize:16];
headerLabel.backgroundColor = [UIColor clearColor];
GRect imageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
UIImageView *headerImage = [[UIImageView alloc] initWithFrame:imageRect];
UIImage *image = [UIImage imageNamed:self.imagePath];
[headerImage setImage:image];
headerImage.opaque = YES;
[containerView addSubview:headerLabel];
[containerView addSubview:headerImage];
self.tableView.tableHeaderView = containerView;
Thanks for reading.
Just adjust the views' frames accordingly. The container view's frame must be tall enough to contain the label and image view, and the image view's y coordinate must be set so that it is positioned below the label. The frame rects you are using in your code do not match.
Related
I want to add some UILabels on top of my UIImagePickerController's custom OverlayView but can't seem to get it working.
Here is my code.
-(IBAction)getPhoto:(id)sender{
picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera ;
picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
OverlayView = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,1024)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(OverlayView.frame.size.height/2, OverlayView.frame.size.width/2, 30, 100)];
label.textColor = [UIColor whiteColor];
label.text = #"find Me";
[self.OverlayView addSubview:label];
[self.OverlayView bringSubviewToFront:label];
picker.cameraOverlayView = OverlayView;
CGSize screenSize = [[UIScreen mainScreen] bounds].size; // 320 x 568
float scale = screenSize.height / screenSize.width*3/4; // screen height divided by the pickerController height ... or: 568 / ( 320*4/3 )
CGAffineTransform translate=CGAffineTransformMakeTranslation(0,(screenSize.height - screenSize.width*4/3)*0.5);
CGAffineTransform fullScreen=CGAffineTransformMakeScale(scale, scale);
picker.cameraViewTransform =CGAffineTransformConcat(fullScreen, translate);
[self presentViewController: picker animated:YES completion:NULL];
}
the overview shows up and it is full screen but no label
any ideas
Your label is just offscreen, check its frame
You can place it for instance like that, at least it will be visible
self.overlayView = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(self.overlayView.frame.size.width/2, self.overlayView.frame.size.height/2, 30, 100)];
I have a relatively simple comment box (UITextfield) for a photo app into which I've found that when entering long comments (usually more than half a dozen words) a lot of blank space appears below the timestamp ("X minutes ago") within the comment box. The longer the post, the more blank space appears within the box. Everything else works fine, the comment is vertically aligned correctly, and the timestamp is directly below this.
self.backgroundColor = [UIColor clearColor];
mainView = [[UIView alloc] initWithFrame:CGRectMake( 20.0f, 0.0f, 280.0f, 51.0f)];
mainView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BackgroundComments.png"]];
[self addSubview:mainView];
UIImageView *messageIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"IconAddComment.png"]];
messageIcon.frame = CGRectMake( 9.0f, 17.0f, 19.0f, 17.0f);
[mainView addSubview:messageIcon];
UIImageView *commentBox = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:#"TextFieldComment.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5.0f, 10.0f, 5.0f, 10.0f)]];
commentBox.frame = CGRectMake(35.0f, 8.0f, 237.0f, 35.0f);
[mainView addSubview:commentBox];
commentField = [[UITextField alloc] initWithFrame:CGRectMake( 40.0f, 10.0f, 227.0f, 31.0f)];
commentField.font = [UIFont systemFontOfSize:14.0f];
commentField.placeholder = #"Add a comment";
commentField.returnKeyType = UIReturnKeySend;
commentField.textColor = [UIColor colorWithRed:73.0f/255.0f green:55.0f/255.0f blue:35.0f/255.0f alpha:1.0f];
commentField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[commentField setValue:[UIColor colorWithRed:154.0f/255.0f green:146.0f/255.0f blue:138.0f/255.0f alpha:1.0f] forKeyPath:#"_placeholderLabel.textColor"];
[mainView addSubview:commentField];
Any help would be much appreciated!
I used the below codes
CGRect scrollserviceViewFrame1 = CGRectMake(60,610, 650, 150);
//CGRect scrollViewFrame =[[UIScreen mainScreen] applicationFrame];
//UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
UIScrollView *servicescrollView1 = [[UIScrollView alloc] initWithFrame:scrollserviceViewFrame1];
[self.view addSubview:servicescrollView1];
//scrollView.backgroundColor=[UIColor greenColor];
[servicescrollView1 setBackgroundColor:[UIColor redColor]];
[servicescrollView1 setCanCancelContentTouches:NO];
//scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
servicescrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
servicescrollView1.scrollEnabled = YES;
servicescrollView1.autoresizesSubviews=YES;
[servicescrollView1 setContentSize: CGSizeMake(1050, 100)];
//scrollView.delegate = self;
servicescrollView1.pagingEnabled = YES;
servicescrollView1.showsHorizontalScrollIndicator = NO;
[servicescrollView1 scrollRectToVisible:CGRectMake(servicescrollView1.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES];
NSLog(#" scroll view width :%i ",servicescrollView1.frame.size.width);
NSLog(#"scroll view height :%i ",self.view.frame.size.height);
NSLog(#"self view width :%i",self.view.frame.size.width);
CGRect CGRectZero = CGRectMake(60,710,200, 100);
UIView* myserviceView1 = [[UIView alloc] initWithFrame: CGRectZero];
myserviceView1.backgroundColor=[UIColor blackColor];
[servicescrollView1 addSubview:myserviceView1];
[myserviceView1 release];
[servicescrollView1 release];
The scroll view is created , butcannot add the UIVIew to scrollview...
Any suggestions for solving this query???
Thanks in advance
Near the bottom of your code where you create myserviceView1, you (attempt to) reset a constant (CGRectZero).
And then when you create your myserviceView1 UIView, you're giving it a frame size of {0, 0, 0, 0}.
I am creating a custom uiview that contains an uilabel and an uiimage assigned to an uiimageview. I assign the custom uiview to the uitableview headerview but i only see the uilabel not the uiimage...please help this is my code...
UIView *containerView1 =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 30)];
UILabel *headerLabel1 =[[UILabel alloc]initWithFrame:CGRectMake(75, 4, 300, 20)];
headerLabel1.userInteractionEnabled = YES;
headerLabel1.text = [NSString stringWithFormat:#"- Latest update %# -", now];
headerLabel1.textColor = [UIColor brownColor];
headerLabel1.shadowOffset = CGSizeMake(0, 1);
headerLabel1.font = [UIFont boldSystemFontOfSize:13];
headerLabel1.backgroundColor = [UIColor clearColor];
UIImage *image = [UIImage imageNamed:#"line_seperator.png"];
UIImageView *imageView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(0.0, 0.0, 30, 30)];
imageView.image = image;
imageView.contentMode = UIViewContentModeScaleAspectFit;
[containerView1 addSubview:headerLabel1];
[containerView1 addSubview:imageView];
[containerView1 addSubview:indicator2];
walltable.tableHeaderView = containerView1;
Any help appreciated.
Forgot to say that this code executes after the uitableview loads.
I have found it. The image was not right. The image was downloaded from the web as .gif . I opened it in photoshop and saved it as .png but it did not saved correctly. I created a new image in photoshop and copy the one i had in that new image. I saved it as .png and it worked.
I try to set the frame of a UITableView to (190,0,610,768) in landscape mode. The frame parameters are correctly set but display is not correct.
To contrast the result, I added a UIlabel with same frame to the bottom:
CGRect frame = CGRectMake(190, 0, 610, 768);
UILabel *lbtb = [[UILabel alloc] initWithFrame:frame];
lbtb.backgroundColor = [UIColor cyanColor];
lbtb.text = #"";
[self.view addSubview:lbtb];
dishMenuVC = [[DishMenuViewController alloc] init] ;
dishMenuVC.view.frame = frame;
dishMenuVC.view.backgroundColor = [UIColor redColor];
dishMenuVC.view.alpha = 0.5;
[self.view addSubview:dishMenuVC.view];
I found a workaround to this problem by creating a container UIView with my intended frame and add the tableview to its subview.