UITextView does not scroll, assistance needed - ios

The following snippet shows up on the screen on top of correct background, however text does not scroll.
What am i missing please?
-(void) viewWillAppear:(BOOL)animated {
UITextView *scrollableText = [[UITextView alloc] initWithFrame:CGRectMake(20, 20, 300, 800)];
[scrollableText setOpaque:TRUE];
[scrollableText setBackgroundColor:[UIColor clearColor]];
[scrollableText setEditable:NO];
[scrollableText setText:#"some really really long text"];
[scrollableText setScrollEnabled:YES];
UIImage *backgroundImage = [[UIImage alloc] initWithCGImage:[UIImage imageNamed:#"about_bg.png"].CGImage];
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:backgroundImage];
[backgroundView addSubview:scrollableText];
[[self view] addSubview:backgroundView];
}

Try [textview setUserInteractionEnabled:YES] or textView.userInteractionEnabled = YES; in addition to setScrollEnabled.

i have the same problem and i resolve in this mode.
Put in your view a customView like OBGradientView and in this add your textView.
in the code add at view your ObGradientView and at it add textview.
work 100% trust to me
here the link for subview

Related

Visible text of UITextView in UIScrollView which has subview UIImageView

when typing in the UITextView the text is not visible;
when typing is done the text is not visible.
How to make it visible?
The code is below. I do not put the UITextView related code intentionally as only font and alignment properties are set.
// Setup the background image view.
[self.backgroundImageView setBackgroundColor:[UIColor blackColor]];
[self.view sendSubviewToBack:self.backgroundImageView];
// Set the image view.
CGRect r = CGRectMake(0, 0, self.TextView.bounds.size.width, 455);
ImageView = [[UIImageView alloc] initWithFrame:r];
// Set up the scroll view for the image zooming in/out and scrolling.
imgScrollView = [[UIScrollView alloc] initWithFrame:ImageView.bounds];
[imgScrollView setScrollEnabled:YES];
[imgScrollView setClipsToBounds:YES];
[imgScrollView addSubview:ImageView];
[imgScrollView setBackgroundColor:[UIColor clearColor]];
[imgScrollView setContentSize:ImageView.frame.size];
imgScrollView.maximumZoomScale = 5.0;
imgScrollView.delegate = self;
UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(scrollViewDoubleTapped:)];
doubleTapRecognizer.numberOfTapsRequired = 2;
doubleTapRecognizer.numberOfTouchesRequired = 1;
[imgScrollView addGestureRecognizer:doubleTapRecognizer];
[imgScrollView sendSubviewToBack:self.TextView];
[self.view addSubview:imgScrollView];
UPDATE
[imgScrollView addSubview:self.TextView];
the line of code above solved this.

rightView property error in iOS7 for UITextField

I am setting an imageView as the rightView of a textfield. This is my code:
UITextField *textField = [[UITextField alloc]initWithFrame:controlFrame];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
[textField setBackgroundColor:[UIColor whiteColor]];
CGRect imageViewFrame = CGRectMake(controlFrame.origin.x + controlFrame.size.width - 20,controlFrame.origin.y, 15.0,controlFrame.size.height-10);
UIImage *image = [UIImage imageNamed:#"arrow.png"];;
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setBackgroundColor:[UIColor clearColor]];
[imageView setFrame:imageViewFrame];
[textField setRightViewMode:UITextFieldViewModeAlways];
textField.rightView = imageView;
Its working perfect on iOS 6.1 devices
But in iOS 7 devices
Any Solution for this?
Thanks in advance
Was just working on this myself and used this solution:
- (CGRect) rightViewRectForBounds:(CGRect)bounds {
CGRect textRect = [super rightViewRectForBounds:bounds];
textRect.origin.x -= 10;
return textRect;
}
This will move the image over from the right by 10 instead of having the image squeezed up against the edge in iOS 7.
Additionally, this was in a subclass of UITextField, which can be created by:
Create a new file that's a subclass of UITextField instead of the default NSObject
Add a new method named - (id)initWithCoder:(NSCoder*)coder to set the image
- (id)initWithCoder:(NSCoder*)coder {
self = [super initWithCoder:coder];
if (self) {
self.clipsToBounds = YES;
[self setRightViewMode:UITextFieldViewModeUnlessEditing];
self.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"textfield_edit_icon.png"]];
}
return self;
}
You may have to import #import
Add the rightViewRectForBounds method above
In Interface Builder, click on the TextField you would like to subclass and change the class attribute to the name of this new subclass
There's another faster option, no need to subclass your uitextfield. There's an example
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 6)];
[imageView setImage:[UIImage imageNamed:#"grey_filter.png"]];
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 6)];
[paddingView addSubview:imageView];
Just create a View bigger than your image with your padding. Add your UIImageView and then put it as left/right view in your textfield.

Transparent Context in IOS?

I'm displaying an image in a UIScrollView but I want it to blend with a UIImageView which is laid behind the UIScrollView.
I'm currently trying to override - (void)drawRect:(CGRect)rect in a subclass of UIView created to display the image inside the scrollview, using either the method drawInRect:blendMode:alpha: or CGContextSetBlendMode but none worked. I think the reason is that the current context is opaque but I cannot find a workaround.
You can add UIImageView as a subclass of UIView (parent view of your scroll view).
You can change opacity of your UIImageView to match your criteria. If you just want a image as a background of your UIView you can set up background of your view and as a colour you can use [UIColor colorWithPatternImage:Your UIImage here].
Is it something you need?
//EXTENDED
I try it and both of the example below set the image as a background and when I scroll the image is not moving:
Example 1:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"newtons_cradle.jpg"]]];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[scrollView setContentSize:CGSizeMake(self.view.bounds.size.width, 1000.0f)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 300, 50)];
[label setBackgroundColor:[UIColor whiteColor]];
[label setText:#"Label Test Text"];
[scrollView addSubview:label];
[self.view addSubview:scrollView];
Example 2:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
[imageView setImage:[UIImage imageNamed:#"newtons_cradle.jpg"]];
[self.view addSubview:imageView];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[scrollView setContentSize:CGSizeMake(self.view.bounds.size.width, 1000.0f)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 300, 50)];
[label setBackgroundColor:[UIColor whiteColor]];
[label setText:#"Label Test Text"];
[scrollView addSubview:label];
[self.view addSubview:scrollView]
;

How to create a multiline navigation bar similar to the one in WhatsApp in iOS?

Does anyone have a clue on how to create a multiline navigation/top bar in iOS? I want something similar to the status line in WhatsApp (the one that displays last seen or the current status information).
Any advice would be appreciated.
I want to achieve something like in the image (Francis Whitman / last seen [...]):
By default, a UINavigationController will use the title property of the currently-displayed view controller for the title in its navigation bar. You can have it display any arbitrary view, however, by setting the titleView property of the view controller’s navigationItem property, as so:
// In your view controller’s implementation (.m) file:
- (id)initWithNibName:(NSString *)nibName
bundle:(NSStirng *)nibBundle
{
self = [super initWithNibName:nibName bundle:nibBundle];
if (self) {
UIView *myTitleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,
0.0f,
250.0f,
44.0f)];
[myView setBackgroundColor:[UIColor greenColor]];
[[self navigationItem] setTitleView:myTitleView];
}
return self;
}
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width/2, 200)];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setTextAlignment:NSTextAlignmentCenter];
[label setNumberOfLines:0];
[label setText:_certificate.name];
self.navigationItem.titleView = label;

creating uiview programmatically?

Creating a view with following code.
- (void)loadView {
paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
[paintView setBackgroundColor:[UIColor yellowColor]];
self.view = paintView;
[paintView release];
But my problem is whole screen fills with yellow color, but I want with specified frame.
I am creating this view in a view based application.. Am i doing something wrong, Overridind the original view?
You can do it in following way.
- (void)loadView {
/// make a empty view to self.view
/// after calling [super loadView], self.view won't be nil anymore.
[super loadView];
paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
[paintView setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:paintView];
[paintView release];
};
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,35)];
newView.backgroundColor=[UIColor clearColor];
UITextView *mytext = [[UITextView alloc] initWithFrame:CGRectMake(5.0, 0.0, 100.0, 28.0)];
mytext.backgroundColor = [UIColor clearColor];
mytext.textColor = [UIColor blackColor];
mytext.editable = NO;
mytext.font = [UIFont systemFontOfSize:15];
mytext.text = #"Mytext";
mytext.scrollEnabled=NO;
[mytext release];
[newView addSubview:mytext];
[self.view addSubview:newView];
replace self.view =paintView;
by
[self.view addSubview: paintView];
I am Going change Line No 3 in LoadView Method , you should add the subView in main View instead on assiging it Directly.
[self.view addSubview:paintview];

Resources