I have a UIView subclass called BackgroundText to draw some text.
-(void) drawRect:(CGRect)rect
{
[#"synchronized." drawInRect:CGRectMake(0, 29, 320, 60) withFont:bigFont lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentRight];
}
--
backgroundText = [[MMRoomBackgroundText alloc] initWithFrame:CGRectMake (0, 142 + 44, 320, 80)];
[self.view addSubview:backgroundText];
I expect [backgroundText removeFromSuperview]; can remove these text from screen,but it doesn't work.
Thanks.
You need to call setNeedsDisplay on the view and check.
I hope this will help you.
Here LoadingBG is My View And LoadingText is My Label And I am Putting Text in Label and Add Label into View and After that I remove View From SuperView When I dont Need Text.
For Adding Text:
UIView * LoadingBG = [UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460);
UILabel *LoadingText = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)] autorelease];
LoadingText.text = #"Loading...";
LoadingText.backgroundColor = [UIColor clearColor];
[LoadingBG addSubview:LoadingText];
For Remove Text:
[LoadingBG removeFromSuperview];
And Here I had Use Fixed Size For View And Label. You can Use What You want as a frame.
Related
I have UITextView in my iPhone app. In the UITextView i have added UIImageView as subview. When the entered text reaches the final height the texts are scrolling to top. Instead the UIImageView (with image) also scrolling top. How can i handle to stop the image scroll and allow the text to scroll? Here is my code for your reference,
messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
messageTextView.delegate = self;
messageTextView.backgroundColor = [UIColor clearColor];
messageTextView.clipsToBounds = YES;
messageTextView.font = [UIFont fontWithName:#"Helvetica" size:14];
messageTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
textViewImageView = [[UIImageView alloc]initWithFrame: CGRectMake(0, 0, 210, 30)];
textViewImageView.image = [UIImage imageNamed: #"textbg.png"];
textViewImageView.contentMode = UIViewContentModeScaleToFill;
textViewImageView.contentStretch = CGRectMake(0.5, 0.5, 0, 0);
[messageTextView addSubview: textViewImageView];
[messageTextView sendSubviewToBack: textViewImageView];
[messageTextView addSubview:textViewLabel];
Can anyone please help me to solve this? Thanks in advance. Looking forward your reply.
have you considered to position the imageView behind the textView? Or is there any reason that forbids such a layout?
something like that:
UITextView *messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
// ...
messageTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:messageTextView];
UIImageView *textViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
// ...
textViewImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:textViewImageView];
[self.view sendSubviewToBack:textViewImageView];
Maybe this could help.
Use the scrollview delegate to reposition your image when it reaches the bounds.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
CGRect imageFrame = textViewImageView.frame;
imageFrame.origin.y = scrollView.contentOffset.y - (scrollView.contentSize.height - scrollView.frame.size.height);
textViewImageView.frame = imageFrame;
}
}
This should work:
[yourTxtView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"your image.png"]]];
I am trying to add a UILabel programmatically into my UIToolBar but it dose not seem to be appearing. This is what I am doing with my code.
- (void) viewWillAppear:(BOOL)animated
{
// Create custom toolbar at top of screen under navigation controller
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
matchingSeriesInfoToolBar = [UIToolbar new];
[matchingSeriesInfoToolBar sizeToFit];
CGFloat toolbarHeight = 30;
CGRect mainViewBounds = [[UIScreen mainScreen] applicationFrame];
[matchingSeriesInfoToolBar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 0, CGRectGetWidth(mainViewBounds), toolbarHeight)];
matchingSeriesInfoToolBar.tintColor = [UIColor darkGrayColor];
[self.view addSubview:matchingSeriesInfoToolBar];
// Create size of uitableview (to fit toolbar.
[matchingSeriesTableView setFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 30)];
[self.view addSubview:matchingSeriesTableView];
// Ad UILabel to the toolbar
UIBarButtonItem *textFieldItem = [[UIBarButtonItem alloc] initWithCustomView:manufSelectionLabel];
matchingSeriesInfoToolBar.items = [NSArray arrayWithObject:textFieldItem];
manufSelectionLabel.text = #"Hello World!";
[super viewWillAppear:animated];
}
So pretty much I have created a custom toolbar which I have changed the usual location from the bottom of the screen, to appear under the UINavigationController, this is also added to the view like this so it animated properly in the view transitions..
After which I create the size of the tableview so that it appears after the custom toolbar..
then from there I am trying to add a UILabel to the toolbar.. but for some reason its not working out.
Any help would be greatly appreciated.
You must actually create the label somewhere. This code works just fine.
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:toolbar];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
label.backgroundColor = [UIColor clearColor];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:label];
toolbar.items = [NSArray arrayWithObject:item];
label.text = #"Hello World";
In the code you posted you don't ever make a UILabel. Your comment says Ad UILabel to the toolbar but you then proceed to make a UIBarButtonItem with a custom view manufSectionLabel.
Where is the code which creates manufSectionLabel?
PS This line does nothing :
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
because at that point matchingSeriesInfoToolbar is nil - you haven't made it yet!
I have a subview that shows once a button is pushed and it shows up fine. I have the subview showing a label along with it. I am just lost on how to change the background color of it and give it some transparency by adjusting it's alpha and setting the label's text color to something else. I know this is just like three to four lines of simple code but I'm at a lost now.
Here is my code:
- (IBAction)showInfo:(id)sender
{
UIView *mySubview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[self.view addSubview:mySubview];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 50)];
label.text = #"This is a label";
[self.view addSubview:label];
}
It all runs fine, I'm just missing some pieces
Try out this code:
mySubview.backgroundColor = [UIColor colorWithRed:.5 green:.6 blue:.7 alpha.8]; // for example
label.textColor = [UIColor redColor];
Hope this help you.
I am confused regarding auto-complete bubble location while entering data in UITextView.
What i have observed is that depending upon its frame's origin , auto-complete bubble either comes on top or bottom. There is no fixed location, provided scrollEnabled is set to NO.
Here are the two links. Code is written in init()
http://www.flickr.com/photos/26021742#N00/6975525835/
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 41)] autorelease];
view.backgroundColor = [UIColor grayColor];
[self.view addSubview:view];
UITextView *growingTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, 200, 27)];
growingTextView.font = [UIFont fontWithName:#"Helvetica" size:13];
growingTextView.scrollEnabled = NO;
[view addSubview:growingTextView];
http://www.flickr.com/photos/26021742#N00/6975525727/
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 41)] autorelease];
view.backgroundColor = [UIColor grayColor];
[self.view addSubview:view];
UITextView *growingTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, 200, 27)];
growingTextView.font = [UIFont fontWithName:#"Helvetica" size:13];
growingTextView.scrollEnabled = NO;
[view addSubview:growingTextView];
Can anyone explain this observed behavior ???
I know that popovers and bubbles will always automatically adjust it's position for ease of use. It's already on Apple's code and in both images the bubble position makes sense.
i added an image to the scroll view. but its not scrolling...
pls help out what is the problem..
Thanks.
boxImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 44, 320, 372)];
boxImage.image = [UIImage imageNamed:#"chapter1box.png"];
textScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 175, 320, 755)];
scrollTextImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 775)];
scrollTextImg.image = [UIImage imageNamed:#"chapter1narrationtext.png"];
textScroll.backgroundColor = [UIColor clearColor];
textScroll.scrollEnabled = YES;
textScroll.pagingEnabled = YES;
textScroll.directionalLockEnabled = YES;
textScroll.autoresizesSubviews = YES;
textScroll.contentSize = CGSizeMake(320, 775);
[self.view addSubview:boxImage];
[boxImage addSubview:textScroll];
[textScroll addSubview:scrollTextImg];
UIImageView has userInteractionEnabled property set to NO by default. Adding
boxImage.userInteractionEnabled = YES;
should help.
The scroll view size has to be smaller than the size of it's content for scrolling to work.
in the code i add the scrollview to an image view
i added it to the self.view its working now.
cant we add a scroll view to an imageview..?