In my appDelegate.m I have this code, but the UILabel is not displaying, but only the UIImageView.
Why?
notificationView = [[UIImageView alloc] initWithFrame: CGRectMake(154, 320, 140, 47)];
notificationView.image = [UIImage imageNamed:#"notification.png"];
NSString *message = [NSString stringWithString:#"New Videos"];
notificationLabel = [[UILabel alloc] initWithFrame: CGRectMake(165, 313, 140, 47)];
notificationLabel.font = [UIFont boldSystemFontOfSize:12];
notificationLabel.textAlignment = UITextAlignmentLeft;
notificationLabel.text = [NSString stringWithFormat:#"%d %#", numberOfVideos, message];
notificationLabel.textColor = [UIColor whiteColor];
notificationLabel.backgroundColor = [UIColor clearColor];
notificationView.alpha = 0.0;
notificationLabel.alpha = 0.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
notificationView.alpha = 1.0;
notificationLabel.alpha = 1.0;
[UIView commitAnimations];
[self.window addSubview: notificationView];
[self.notificationView addSubview: notificationLabel];
[UIView commitAnimations];
[notificationView release];
[notificationLabel release];
notificationLabel is a subview of notificationView.
It is placed out of bounds of its superview.
Try
notificationLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 140, 47)];
and go from there. For all subviews, the top left corner of a super view is (0, 0).
The width of the notification view is 140. Your label is being placed at an X location of 165 within the notification view, which is out of the bounds of the notification view. So it isn't visible.
Related
I am creating a app that display subview like ActionSheetView and in that i have added UIGridView and UIPageControll thru outlet , but now when i click the cell it does not respond ,my subview is a ViewController with the nib file.
and if i create a button and add in my popupview programmatically then it wil displaying, and also get the click event, but anything in outlet does not respond.
i have tried to set userinteraction enable in my subview but it does not done any good.
here is my code for first view that display subview by clicking barbutton:
- (void)popUpView:(id)sender {
//self.view.backgroundColor = [UIColor darkGrayColor];
bGView = [[UIView alloc] init]; /this is the background view and all view is added in it
bGView.frame = CGRectMake(0,0,320,490);
bGView.backgroundColor = [UIColor clearColor];
bGView.alpha = 0.8 ;
CGRect viewFrame = CGRectMake(10, 90, 300, 300);
aPopUpViewController = [[PopUpViewController alloc] initWithNibName:#"PopUpViewController" bundle:nil]; //this is my view controller and when this shows on screen it display my greed view
aPopUpViewController.view.frame = viewFrame;
aPopUpViewController.view.userInteractionEnabled = YES;
[bGView addSubview:aPopUpViewController.view];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
button.backgroundColor = [UIColor clearColor];
[button setBackgroundImage:[UIImage imageNamed:#"close_button.png"] forState:UIControlStateNormal];
button.frame = CGRectMake(-1, 80, 30, 30);
[bGView addSubview:button];
//for view animation
/*
// from bottom to center animation
[bGView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)]; //notice this is OFF screen!
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[bGView setFrame:CGRectMake( 0.0f, 0.0f, 320.0f, 480.0f)]; //notice this is ON screen!
[UIView commitAnimations];*/
//for page like effect
/*[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCurlUp //change to whatever animation you like
animations:^ { [self.view addSubview:bGView]; }
completion:nil];*/
/*CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionReveal; //choose your animation
[bGView.layer addAnimation:transition forKey:nil];
[self.view addSubview:bGView];*/
aPopUpViewController.view.userInteractionEnabled = YES;
bGView.userInteractionEnabled = YES;
self.view.userInteractionEnabled = YES;
bGView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
bGView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// do something once the animation finishes, put it here
}];
[self.view addSubview:bGView];
addLabel.enabled = NO;
clipArt.enabled = NO;
emailItem.enabled = NO;
closeButton.enabled = NO;
self.navigationController.topViewController.title = #"Choose ClipArt";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.navBarHide = #"no";
}
- (void)aMethod:(id)sender
{
//[aPopUpViewController.view removeFromSuperview];
//[button removeFromSuperview];
/*[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve//change to whatever animation you like
animations:^ { [bGView removeFromSuperview]; }
completion:nil];*/
[bGView removeFromSuperview];
addLabel.enabled = YES;
clipArt.enabled = YES;
emailItem.enabled = YES;
closeButton.enabled = YES;
self.navigationController.topViewController.title = #"Greeting's";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.navBarHide = #"yes";
}
and this is how my screen look like
UPDATE
now i figured out my problem,problem is that i have given my whole view a tap listner,now i am adding grid view as subview so when ever i tap on cell rather then do select cell it will generate view tap gesture and thats why cell never selected,that's what i think..
add this line after you add every subviews in your main view..
[self.view bringSubviewToFront:yourGridView];
I have an application in which a pickerview is ther with images.I had done that with this.`
picker1=[[UIPickerView alloc] init];
picker1.frame= CGRectMake(30,90,155,316);
picker1.delegate = self;
picker1.dataSource = self;
picker1.showsSelectionIndicator = YES;
picker1.tag = 1;
[self.view addsubview:picker1];
and i am using viewForRow delegate methode to load the images.i need to increase the images frame there inside the pickerview.`
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:#"%#.png",[self.array objectAtIndex:row]]];
UIImageView *icon = [[UIImageView alloc] initWithImage:img];
//temp.frame = CGRectMake(170, 0, 30, 30);
UIView *tmpView = [[[UIView alloc] initWithFrame:CGRectMake(155,75,95,35)] autorelease];
[tmpView insertSubview:icon atIndex:0];
picker1.backgroundColor = [UIColor clearColor];
[(UIView*)[[picker1 subviews] objectAtIndex:2] setAlpha:0.0f];
[(UIView*)[[picker1 subviews] objectAtIndex:0] setAlpha:0.0f];
[(UIView*)[[picker1 subviews] objectAtIndex:1] setAlpha:0.0f];
[(UIView*)[[picker1 subviews] objectAtIndex:3] setAlpha:0.0f];
[tmpView setUserInteractionEnabled:NO];
[tmpView setBackgroundColor:[UIColor clearColor]];
[tmpView setTag:row];
return tmpView;
but when i try to increase the frame of the view its position only changing,not the size.can anybody help me to achieve this?
implement the following pickerview delegate method..
- (CGSize)rowSizeForComponent:(NSInteger)component{
CGSize size = CGSizeMake(320, 60); //input ur custom size
return size;
}
I have table view with a UITextView added in the footer. I want my table view to animate to top once user tap on the textview. This is done with below piece of code but I have to set the height to negative. Is there any other way of doing this?
- (void)textViewDidBeginEditing:(UITextView *)iTextView {
[UIView animateWithDuration:0.4
delay:0
options:UIViewAnimationTransitionFlipFromLeft
animations:^{
self.myTextView.frame = CGRectMake(8, 4, 200, -160);
self.myTextView.text = #"test";
self.myTextView.font = [UIFont systemFontOfSize:14];
self.myTextView.textColor = [UIColor blackColor];
}
completion:^(BOOL finished){
self.myLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, self.feedbackTextView.frame.size.height + kRunnerTopBottomMargin, kScreenWidth, 20.0f)] autorelease];
self.myLabel.backgroundColor = [UIColor clearColor];
self.myLabel.textColor = [UIColor darkGrayColor];
self.myLabel.text = #"default";
self.myLabel.textAlignment = UITextAlignmentCenter;
self.myLabel.font = [UIFont systemFontOfSize:12];
[self.view addSubview:self.myLabel];
}];
You can call this method:
[YourTableView setContentOffset:CGPointMake(0.0f, 0.0f) animated:YES];
Perhaps this can help you.
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
I made a UIView subclass (bowl) and when I try to make a bowl within a bowl and then center the inner one on the outer one's center it end up getting placed below and to the right of the center. How would I properly center it?
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
//CGColorRef lightGrayColor = [UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1.0].CGColor;
self.userInteractionEnabled = YES;
UIGestureRecognizer *twoFingerZ = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(pinchZoom:)] ;
[self addGestureRecognizer:twoFingerZ];
UILabel *label = [[UILabel alloc] init];
[label setFont:[UIFont fontWithName:#"Arial" size:64]];
label.text = [NSString stringWithFormat:#"March"];
[label sizeToFit];
label.center = self.center;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor lightGrayColor];
self.backgroundColor = [UIColor whiteColor];
[self addSubview:label];
}
return self;
}
-(void)pinchZoom:(UIPinchGestureRecognizer *)recognizer
{
if([(UIPinchGestureRecognizer*)recognizer state] == UIGestureRecognizerStateEnded) {
CGAffineTransform newForm = CGAffineTransformMakeScale(600/self.bounds.size.width, 600/self.bounds.size.height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self setTransform:newForm];
return;
[UIView commitAnimations];
}
if([(UIPinchGestureRecognizer*)recognizer state] == UIGestureRecognizerStateBegan) {
subClip = [[clipView alloc] initWithFrame:CGRectMake((self.center.x - ([delegate getSize:self].width/2)), (self.center.y - ([delegate getSize:self].height/2)), [delegate getSize:self].width, [delegate getSize:self].height)];
subClip.transform = CGAffineTransformMakeScale(0.1, 0.1);
[self addSubview:subClip];
bowl *newB = [[bowl alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];
newB.center = self.center;
// right here! *************
[self addSubview:newB];
}
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = 1;
}
EDIT: I fixed it. Apparently the center value for a UIView isn't exactly what I thought it was (it looks like it's the position of the center in another view or something), so instead of newB.center = self.center, the right way to do it was newB.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
To center the inner label you should be able to use:
label.center=CGPointMake(self.center.x,self.center.y);
But first you'll probably want to define the frame size of the inner label:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,yourWidth,yourHeight);
You may also want to center the text within the inner label:
label.textAlignment = UITextAlignmentCenter;
Also, not sure what you're intending in your code with this:
[label sizeToFit];
But according to the documentation, sizeToFit will resize and moves the receiver view so it encloses its subviews. In this case, it doesn't appear that your inner view has subviews. So your centering may be off because you may have unexpected dimensions for your inner label. Try setting the background color for that label to something you can see (i.e. not [UIColor clearColor]) to double check its dimensions. May help solve the centering problem.
Good luck.
I have a UIView with another UIView inside it. On the inside UIView there is a textbox which I want to fill in. When I try to fill it in the keyboard blocks my view:
The UIViewController has the following
containerView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view=containerView;
//The apropriate releases etc are further on...
When I touch it, the keyboard comes up as expected, but blocks the textbox I'm trying to fill in. How can I force the view to slide up?
The front view
OptionsFront * fv = [[OptionsFront alloc] initWithFrame:[UIScreen mainScreen].bounds];
[containerView addSubview:frontView];
In the front view is a subview
CGRect bounds = CGRectMake(0.0f, 210.0f, 280.0f, 130.0f);
sv = [[UIView alloc] initWithFrame:bounds];
[self addSubview:sv]; //added to frontView
In sv is a textbox near the botton:
rect = CGRectMake(70.0f, 20.0f, 100.0f, 27.0f);
cf = [self createTextField_Rounded:rect holder:#"+ve"];
[sv addSubview:cf];
So cf happens to be near the bottom of the page. I expected that when I select it, the whole display would move up, but the keyboard just moves up and blocks it.
What can I do?
Appendix:
- (UITextField *)createTextField_Rounded:(CGRect) frame holder:(NSString *) ph
{
UITextField *returnTextField = [[UITextField alloc] initWithFrame:frame];
returnTextField.borderStyle = UITextBorderStyleRoundedRect;
returnTextField.textColor = [UIColor blackColor];
returnTextField.font = [UIFont systemFontOfSize:17.0];
returnTextField.delegate = self;
returnTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
returnTextField.returnKeyType = UIReturnKeyDone;
returnTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
return returnTextField;
}
you need to move the textField up. in your UITextField delegate implement something like (from memory):
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
textField.superview.frame = CGRectMake(0.0f, 100.0f, 280.0f, 130.0f); // experiment with frame size
[UIView commitAnimations];
}
and you'll want to move it back in textFieldDidEndEditing: