since new Xcode 6 came, I struggle with some problem. I can't resize the frame of inputAccessoryView.
I use custom inputAccessoryView (resizable) for UITextField, which has as a subview UITextview. To resize content, I used to change the frame of accessoryView, and it worked. Now it has always the same init size.
Everything works perfect on previous iOS 7.
frist, get inputAccessoryView and set nil
UIView *inputAccessoryView = yourTextView.inputAccessoryView;
yourTextView.inputAccessoryView = nil;
[yourTextView reloadInputViews];
then set frame and layout
inputAccessoryView.frame = XXX
[inputAccessoryView setNeedsLayout];
[inputAccessoryView layoutIfNeeded];
last set new inputAccessoryView and reload
yourTextView.inputAccessoryView = inputAccessoryView;
[yourTextView reloadInputViews];
Related
How get UITextView contentView height, if Iam using sizeToFit property ?
if you are using,
int numLines = txtview.contentSize.height / txtview.font.lineHeight;
to get the number of lines in the textView then you don't need sizeToFit or not required to set textView's frame as per content size.
txtview.contentSize.height will give you content view's height and you can get number of lines.
But make sure that you are doing this in viewDidAppear(or any where after your view is appeared) not in viewDidload because in viewDidload your textview is not loaded completely.
UITextView itself has a function called sizeThatFits: which will return the smallest size needed to display all contents of the UITextView inside a bounding box, that you can specify.
The following will work equally for both iOS 7 and older versions and as of right now does not include any methods, that are deprecated.
- (CGFloat)textViewHeightForAttributedText: (NSAttributedString*)text andWidth: (CGFloat)width {
UITextView *calculationView = [[UITextView alloc] init];
[calculationView setAttributedText : text];
CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
return size.height;
}
Reference link UITableViewCell with UITextView height in iOS 7?
I'm using UIPageViewController in my app that has 3 pages. On third page, there is a UITextView but that doesn't scroll when it has text bigger than its frame size. What could be wrong here?
set size of textview by its contentSize property
CGRect myFrame = self.myTextView.frame;
myFrame.size.height = self.myTextView..contentSize.height;
self.myTextView..frame = myFrame;
Or u can also try
[myTextView sizeToFit];
I have one UITextView whose height is 568 (means fit in screen size) and if i write 50 lines in it then it will definitely scroll vertically.
But i want to scroll (or just bounce) when there is only one line of text.
When user scroll Vertically then the text will just bounce in UITextView.
in my application the UITextView is not Editable.
Any idea, code,link will be great help...
EDIT:
The UITextView's height will be that 568 only.
it will not change (means without changing the height of UITextView, set this thing).
[txtView setContentOffset:CGPointMake(0, 1000)];
It is not working too...
If you want to scroll TextView text that not Larger then it height . then you can't do this. you wont getting scroll bar if your textView's Text not larger then its frame height.
Setting [txtView setContentOffset:CGPointMake(0, 1000)]; wont work anymore if that data in not longer then textView's height.
UPDATE:-
Here it is i got one trick. If textview not editable and you just want to scroll it try to add your Textview in to one scrollviw. Like Bellow i got this working.
in .h class
#property(nonatomic,retain)IBOutlet UITextView *textvie;
#property(nonatomic,retain)IBOutlet UIScrollView *sceoll;
in .m class
- (void)viewDidLoad
{
[sceoll setContentSize:CGSizeMake(0, 500)];
[textvie setTextAlignment:NSTextAlignmentCenter];
textvie.editable = FALSE;
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
textvie.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
} else {
textvie.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
}
[super viewDidLoad];
}
in xib
and the result is:-
Set the frame of UITextView
CGRect frame = textView.frame;
frame.size = textView.contentSize;
textView.frame = frame;
See: UITextView change height instead of scroll
The iOS 7 redesign resulted in change of the view hierarchy of UITableViewCells. The content view of the cell was wrapped in a private class called UITableViewCellScrollView.
In iOS 7 UITableViewCellScrollView has clipsToBounds set to YES and UITableViewCellContentView has clipToBounds set to NO.
In iOS 7.1 UITableViewCellScrollView has clipsToBounds set to NO and UITableViewCellContentView has clipToBounds set to NO.
If you call [[self contentView] setClipsToBounds:YES] in iOS 7.1 is does it stick. By the time layoutSubviews is called on the cell UITableViewCellContentView has clipToBounds set to NO again.
[[self contentView] superview] setClipsToBounds:YES] works in iOS 7.1 and sets UITableViewCellScrollView's clipToBounds to YES but this is a very brittle solution.
Overriding layoutSubview on the cell and calling [[self contentView] setClipsToBounds:YES] works but is another fraile solution.
Does anyone know why this change has been made and a more robust solution to it?
As discussed in the comments, the only solution right now in iOS7.1 is to set clipsToBounds on the cell itself.
It's quite annoying. What I did is add an UIView in the contentView with identical size (and autoresizingMask in width), add the relevant content to this view, and set clipsToBounds to it.
I hit the some problem, and I solved this confused problem by an ugly way finally.
// Create a subclass of UITableView
// Then override setClipsToBounds:
- (void)setClipsToBounds:(BOOL)clipsToBounds {
[super setClipsToBounds:YES];
}
In iOS 8, checking the cell's "Clip Subviews" in the XIB did not work.
What does work is:
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.clipsToBounds = YES;
}
I have a XIB file containing a view with a UITextView as subview. This textView is 30px high, because it should resize according to it's content.
So I set the text programmatically, call -sizeToFit and reconfigure the frame of the textView and its superview:
[_textView setText:[contents objectForKey:#"body"]];
[_textView sizeToFit];
CGSize txtSize = _textView.contentSize;
txtSize.height = _textView.frame.size.height;
_textView.contentSite = txtSize;
CGRect superFrame = _textView.superView.frame;
superFrame += _textView.contentSize.height;
_textView.superView.frame = superFrame;
The superView actually does resize correctly. Also, when logging the text views frame and content size, on the console it appears to be okay (about 1200px high).
But the textView is still just 30px high on the screen. Also calling -setNeedsLayout did not do the trick.
What could be the issue here?
This is a bug i ran into a couple of days ago. It seems that UITextView will cut off a part of the text no matter the height if its scroll is disabled.
A solution that works in certain situations is:
[_textView setScrollEnabled:YES];
[_textView setText:text];
[_textView setScrollEnabled:NO];
I have reported this bug to Apple, but I suggest you do the same.