Text in UITextField moves up after editing (center while editing) - iphone

I have a strange problem. I have an UITextField in which the user should write the amount of something, so the field is called "amountField". Everything looks fine, when the user starts editing the textfield the text is in the vertical and horizontal center - that's great.
However, when the user ends editing the text moves up a little bit. I tried many things, nothing helped...
I am adding screenshots below, so you can see what is the problem.
This is what it looks like while editing the field - that's ok.
And this is how it looks when done editing - that is the problem!
Please, if anybody know what could cause this I would be very grateful! :)
Here is some of my code related to the amountField.
amountField.keyboardType = UIKeyboardTypeNumberPad;
amountField.returnKeyType = UIReturnKeyDone;
amountField.delegate = self;
[amountField setFont:[UIFont fontWithName:#"Nuptial Script LT Std" size:30]];
amountField.borderStyle = UITextBorderStyleNone;
UIImage *amountBg = [UIImage imageNamed:#"skin2_ipad_amountField.png"];
[amountField setBackground:amountBg];
amountField.rightView = nil;
//amountField.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.2];
amountField.textAlignment = UITextAlignmentCenter;
amountField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
amountField.adjustsFontSizeToFitWidth = YES;
amountLabel.textColor = UIColorFromARGB(0x313030); //Using my own macro
amountField.frame = CGRectMake(300, 480, 136, 32);
amountField.center = CGPointMake(605, 439);
PS: Those white corners are there because I set the background to white with 0.2 alpha, that's ok.

I had a similar issue that started happening on iOS 9. Basically I have a UITextField in a collection view cell. Sometimes when the user is done typing and editing ends, the text "bounces" up then down again into its correct position. Very strange and annoying glitch. Simply making this tweak fixed the issue on iOS 9 and proved to be safe on iOS 7 and 8:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[textField layoutIfNeeded]; //Fixes iOS 9 text bounce glitch
//...other stuff
}

So...
After many hours of trying many things - I have found the problem.
In my case the problem is the font. I really don't know why, but the author of the font made the font weird (leading etc.), it has a blank space on the bottom. I don't know why, but when you are editing the text all of the text properties are ignored, but after you finish editing, they are applied.
So, if you have a similar problem, try changing the font to Arial or something similar.
For a full explanation, please consult these following links: link 1 and link 2. The solution recommended in these links can avoid you a lot of headaches and can even be applied to fix problem like text moving to the top when you start editing an UITextField (using System font or other particular fonts).

Disabling ClipsToBounds for the TextField solved it for me.

This bug happened to me when I set text & became the first responder in viewDidLoad or viewWillAppear. When I moved the becomeFirstResponder code to viewDidAppear the bug went away.

I'm struggling with this issue almost every time when the design of app is with custom font. One option is to fix the font (but this is too much work – at least for me :) ). The second option I'm using is subclassing the UITextField and overriding the editingRectForBounds: and placeholderRectForBounds: methods and correct the offset. It should work for your case too.
#implementation MyTextFieldWithFixedFontPosition
-(CGRect)editingRectForBounds:(CGRect)bounds{
return CGRectOffset([self textRectForBounds:bounds], 0, 0.5); //0.5 is just example, you can adjust to any offset you like
}
-(CGRect)placeholderRectForBounds:(CGRect)bounds{
return [self editingRectForBounds:bounds];
}
#end
I haven't tested it with leftView or rightView though, so be careful when using these :)
NOTE: this approach is "font dependant", values used for offset may vary for each font and size

There is a glitch on iOS 8.1 and below, I do not know if they will fix it later but at that time there is not an unique solution which fixes all cases, because the bug and the solutions are font's type, size dependent.
One of this solution or a combination of these solutions below can fix your problem:
Changing the font's size.
Changing the font's type.
Changing the UITextField's size.
Decompiling the font in question, modifying the font's characteristics and recompiling it (for more explanation please consult the following links: link 1 and link 2).
Otherwise this other self-sufficient solution below can fix your problem:
Swift version
import UIKit
class CustomTextField: UITextField {
...
override func textRectForBounds(bounds: CGRect) -> CGRect {
// Possible values.
return CGRectInset(bounds, CGFloat(35.0), CGFloat(0.0))
}
override func editingRectForBounds(bounds: CGRect) -> CGRect {
// Possible values.
return CGRectInset(bounds, CGFloat(35.0), CGFloat(0.0))
}
override func placeholderRectForBounds(bounds: CGRect) -> CGRect {
// Possible values.
return CGRectInset(bounds, CGFloat(35.0), CGFloat(0.0))
}
}
This solution has been tested with leftView and works like a charm.
NOTE: this approach is "font dependant", values used for CGRectInset may vary for each font and size.

I fixed this by adding height constraints to my UITextFields.

I wasn't able to change the font file, so when I solved this I saved the original UITextField's frame in a property and applied the following code:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
textField.frame = self.usernameFrame;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
textField.frame = CGRectOffset(self.usernameFrame, 0, 1);
}
It's a bit hacky, but it gets the job done.

I had similar issues with a UITextfield embedded in a UITableViewCell. Where exactly is this code located in your project? What I believe is happening is that after you've finished editing a particular textfield, it sends itself -setNeedsDisplay and its drawRect: is subsequently called. This might explain the shift in alignment. In my particular scenario, I had to use a table view delegate method -willDisplayCell... to set the content alignment. I would have to know more about your design to possibly offer a suggestion.
One potential solution would be to use the text field delegate methods to set the content alignment.
-(void)textFieldDidEndEditing:(UITextField *)textField{
if (amountField == textField){
amountField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
}
}

Check the keyboard to change the view of the position of the pop-up if there is line of code self.view.layoutIfNeeded() Delete it.Good Luck!

This is because the BaselineOffset for the textfield got changed.
In UITextFieldDidEndEditing creating an attributed text with NSBaselineOffset: 0 and using that attributedText would fix the problem.
-(IBAction)txtFieldDidEndEditing:(UITextField *)sender {
NSDictionary *style = #{
NSBaselineOffsetAttributeName: #(0)
};
self.txtField.attributedText = [[NSAttributedString alloc] initWithString:self.txtField.text attributes:style];
}

These solution above doesn't work for me.My solution is subclass UITextField and override setText:
- (void) setText:(NSString *)text {
[super setText:text];
[self layoutIfNeeded];
}

I used this extension. Only problem was I didn't add translatesAutoresizingMaskIntoConstraints = true before I called it. Ah silly goose
func centerVertically() {
textContainerInset = UIEdgeInsets.zero
textContainer.lineFragmentPadding = 5
let fittingSize = CGSize(width: bounds.width, height:
CGFloat.greatestFiniteMagnitude)
let size = sizeThatFits(fittingSize)
let topOffset = (bounds.size.height - size.height * zoomScale) / 2
let positiveTopOffset = max(1, topOffset)
contentOffset.y = -positiveTopOffset
}

Related

iOS 7 UITextView height resize quirk

Using information I've gathered from multiple answers I found here on stackoverflow, I've been able to correctly size a UITextView's height using:
[bookQuoteTxtView sizeToFit];
[bookQuoteTxtView layoutIfNeeded];
I'm doing this because the UITextView will obviously contain different amounts of text as a result of what the user may have selected on a previous screen.
However, I'm still running into one strange problem.
It seems that when the text that gets passed into the UITextView contains a line-break, it throws the whole height thing off.
Here's the text without any line-breaks:
And here's the same text with a couple of line-breaks thrown in the middle:
As you can see (with the help of the orange & yellow background colors I added to the UITextView & ScrollView that contains it), the UITextView's height didn't resize appropriately and now the text gets cut off - all because of those linebreaks.
The code I'm using to do all this dynamic height-changing on the UITextView is:
// BookQuote TextView:
bookQuoteTxtView = [[UITextView alloc] initWithFrame:CGRectMake(5, 30, 310, 80)];
bookQuoteTxtView.backgroundColor = [UIColor orangeColor];
bookQuoteTxtView.font = [UIFont fontWithName:#"Arial" size:15];
bookQuoteTxtView.text = [NSString stringWithFormat:#"%#", bookObject.bookQuote];
[bookQuoteTxtView sizeToFit];
[bookQuoteTxtView layoutIfNeeded];
bookQuoteTxtView.editable = NO;
[scroller addSubview:bookQuoteTxtView];
// Now get the HEIGHT of the Book-Quote TextView:
CGRect textViewFrame = bookQuoteTxtView.frame;
CGFloat textViewFrameHeight = bookQuoteTxtView.contentSize.height;
textViewFrame.size.height = textViewFrameHeight;
bookQuoteTxtView.frame = textViewFrame;
So again, this works almost flawlessly for just about every string that gets passed into my UITextView box. Thus, different strings of different lengths all work, the UITextView's height adjusts automatically and everything's cool. Its just the line-breaks that throw everything off.
HAVING SAID THAT...
Its seems that line-breaks generated using "\n" in the string DO work, but line breaks that are embedded/encoded in a string that's coming in and being read from an Sqlite3 database - do NOT.
So you gotta wonder if that's where the problem lies.
Here's the code I use to read my date from the Database:
// Book Quote:
char *bookQuoteChar = (char *)sqlite3_column_text(statement, 4);
NSString *bookQuoteString;
if (bookQuoteChar == NULL) {
bookQuoteString = #"N/A";
}
else {
bookQuoteString = [[NSString alloc] initWithUTF8String:bookQuoteChar];
}
I'm thinking more and more that its the database that's causing the problem, but I'm presenting the entire picture here in its totality to make sure I'm still doing the height-readjustment stuff correctly.
Please let me know if something's jumping out at you or if there are any suggestions for fixes.
I can't really suggest much besides using a technique to set the contentSize of the UITextView.
textView.text = #"text from DB";
CGRect rect = textView.frame;
rect.size.height = textView.contentSize.height;
textView.frame = rect;
and then use any techniques that may be needed to additionally update the frame. Hope you solve the problem!

UITextField - (void)drawPlaceholderInRect:(CGRect)rect returns different CGRect height in iOS 7

I tried to subclass UITextField to draw custom placehoder. In iOS 6 this works fine but in iOS 7 I got a different CGRect height.
The UITextField frame is (0, 0, 500, 45). I added a left padding of 20 by overriding
- (CGRect)editingRectForBounds:(CGRect)bounds;
- (CGRect)placeholderRectForBounds:(CGRect)bounds;
- (CGRect)textRectForBounds:(CGRect)bounds;
Calling the method below to do so:
- (CGRect)makeRectFromBounds:(CGRect)bounds
withTopPadding:(CGFloat)topPadding
andLeftPadding:(CGFloat)leftPadding
{
return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(topPadding, leftPadding, 0, 0));
}
Because I want a different placeHolder text color, I override
- (void)drawPlaceholderInRect:(CGRect)rect
- (void)drawPlaceholderInRect:(CGRect)rect {
[[UIColor colorWithRed:121.0/255.0
green:113.0/255.0
blue:107.0/255.0
alpha:1.0] setFill];
[self printRect:rect from:__FUNCTION__];
[[self placeholder] drawInRect:rect withFont:self.font];
}
The rectangle I'm printing is the following:
iOS 7: -Rect (X: 0.0, Y:0.0, W:480.0, H:44.0)
iOS 6: -Rect (X: 0.0, Y:0.0, W:480.0, H:26.0)
Any idea if this is a bug or am I doing something wrong?
Use the following instead:
[textfield setValue:[UIColor redColor] forKeyPath:#"_placeholderLabel.textColor"];
In iOS 7 the default value for contentVerticalAlignment changed from "top" to "center" (with no documentation that I could see). In "center" mode iOS adjusts the result of the rectForBounds methods before drawing into them. You should probably set contentVerticalAlignment = UIControlContentVerticalAlignmentTop when overriding any of textRectForBounds methods so iOS will use the rect exactly as specified.
Since iOS7 is new nowadays, so many people faces framing issue with iOS7.
To all of them, I just want say that it is so easy and there isn't any issue with iOS7. It's just because you don't know how to take benefits from the latest OS feature provided by Apple.
#Cyupa : You just need to apply autosizing and mask your textfield.
it could be one or more from following.
UIViewAutoresizingFlexibleBottomMargin
UIViewAutoresizingFlexibleTopMargin
UIViewAutoresizingFlexibleLeftMargin
UIViewAutoresizingFlexibleRightMargin
UIViewAutoresizingFlexibleHeight
UIViewAutoresizingFlexibleWidth
if you apply proper autosizingmask to your textfield, you will get your desired frame for your view (Here textfield)
I also met this problem, not found why yet, but if you want to have the same behavior on both iOS6 and iOS7, you can try this:
- (CGRect)textRectForBounds:(CGRect)bounds {
CGRect rect = [super textRectForBounds:bounds];
rect = CGRectMake(20, rect.origin.y-4, rect.size.width-20, rect.size.height);
return rect;
}
and you may need to set:
theLabel.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;
check the system version and return the UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(topPadding, leftPadding, 0, 0));
you can check device version as
if(([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0))
{
}
i solved issue by using this property
textField.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;
It's working for both iOS6 and iOS7.
Ricky's solution worked for me with the addition this value has to be set each time AFTER placeholder text changed. I overwrote setPlaceholder to do that.
It replaces the need to overwrite drawPlaceholderInRect, if you want another placeholder color, therefore vertical alignment will be correct automatically. Of course this does not answer the question, why IOS 7.0 behaves like that, but it might solve your actual problem.
- (void) setPlaceholder: (NSString*)placeholderText {
[super setPlaceholder:placeholderText];
[self setValue:[UIColor redColor] forKeyPath:#"_placeholderLabel.textColor"];
}
It should be mentioned, that some people discourage this bypassing of public interfaces, so do it on your own risk!
See also:
Change UITextField's placeholder text color programmatically

How can I get the UITextView to scroll only when it's full of text

I have this UITextView that works great except, I can't get the text inside the UITextView to start scrolling only after the UITextView's size in nearly full, the UITextView is 4 lines tall, but as soon as I reach the 2nd line the 1st line is pushed up, I don't want the view to begin scrolling until I've reached the 5 line. scrollingEnabled = NO keeps it from scrolling at all, so that didn't work.
UITextView *barf_ = [[UITextView alloc] initWithFrame:CGRectMake(20.0, 310.0, 155, 50)];
barf_.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
//[barf_ scrollRangeToVisible:NSMakeRange([barf_.text length], 0)];
barf_.layer.cornerRadius = 3.0f;
barf_.layer.borderWidth = 0.5f;
barf_.font = [UIFont fontWithName:#"Helvetica" size:13];
I found the answer, as others with similar problems have mention, with a small textView, it automatically adds 32 padding to the bottom.
A simple fix is to add YourTextView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); inside shouldChangeTextInRange method, that fixed my problem!
Setting the contentInset may help the text to appear more correctly within the UITextView. However, it won't help solve the issue whereby the UITextView has scrolling enabled despite not having more text to view.
Similarly, methods such as sizeWithFont have limitations. As explained in Mike Weller's excellent blog series iOS Development: You're Doing It Wrong, NSString isn't a good object to ask regarding how large a UIView should be. Many UIView subclasses such as UILabel, UIButton, etc. have insets and other considerations that must be accounted for during sizing. UITextLabel is no exception.
Mike Weller's particular entry on this subject is:
You're Doing It Wrong #2: Sizing labels with -[NSString sizeWithFont:...]
iOS 7 promises us more sophisticated text handling in UITextView, with properties such as textContainerInset. But what to do in the meantime?
Well, first we know that UITextView is a subclass of UIScrollView. Therefore, the golden rule that if the contentSize is larger than the view's bounds property, the scroll view will scroll so we can see more content.
Checking out contentSize agains the bounds won't work either because we know that UIScrollView is already calculating whether it should scroll or not based on the text, and it's giving us the wrong answer.
This is where arbitrary adjustment values come to the rescue! For me this value was 17.f. For you - depending on your fonts - it maybe different. We then take control and decide whether we should allow the scroll view to scroll:
static const CGFloat kArbritaryHeight = 17.f;
CGFloat adjustedContentHeight = myTextView.contentSize.height - kArbritaryHeight;
CGFloat boundsHeight = CGRectGetHeight(myTextView.bounds);
BOOL tooMuchContent = adjustedContentHeight > boundsHeight;
if (tooMuchContent)
{
myTextView.scrollEnabled = YES;
}
else
{
myTextView.scrollEnabled = NO;
}
When your UITextView is loaded set scrollEnabled to NO. Then set the text view's delegate to self or some other object and implement the UITextViewDelegate method
- (void)textViewDidChange:(UITextView *)textView
This method will get called anytime the user makes a change to the text inside the view. Inside this method you need to figure out how big your text is and if it goes beyond the bounds of the text view. If so you enable scrolling. Use this method:
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode
This is a UIKit category method on NSString. It returns a CGSize that will tell you the height of whatever text string you call it on. In your case it would be something like
CGSize textSize = [textView.text sizeWithFont:textView.font
constrainedToSize:CGSizeMake(textView.frame.size.width, MAXFLOAT)
lineBreakMode:UILineBreakModeWordWrap];
if (textSize.height > textView.frame.size.height) {
textView.scrollEnabled = YES;
} else {
textView.scrollEnabled = NO;
}
You might use the sizeWithFont:constrainedToSize:lineBreakMode: method to check whether your string will actually render larger than your text view and see if you need to enable scrolling. You will have to call it any time the text in your scrollview is set, however.
ex:
CGSize barfStringSize = [barfString sizeWithFont:[barf_ font]
constrainedToSize:CGSizeMake(barf_.bounds.size.width, MAXFLOAT)
lineBreakMode:UILineBreakModeWordWrap]
[barf_ setScrollEnabled:barfStringSize.height > barf_.bounds.size.height]

UItextView arabic text aligned to right

Using my custom arabic keyboard on UItextView inputView, I m filling my textView with the arabic text but cannot get the written text align to right....Need help to align text to right.
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
if(showCustomKeyboard==NO){
[textView resignFirstResponder];
textView.inputView=nil;
[textView becomeFirstResponder];
return YES;
}
else{
[textView resignFirstResponder];
if(customKeyboard==nil){
customKeyboard=[[CustomKeyboard alloc] initWithFrame:CGRectMake(0, 264, 320, 216)];
[customKeyboard setDelegate:self];
}
if([[UIApplication sharedApplication] respondsToSelector:#selector(inputView)]){
if (textView.inputView == nil) {
textView.inputView = customKeyboard;
[textView becomeFirstResponder];
}
}
self.customKeyboard.currentField=textView;
[textView becomeFirstResponder];
}
return YES;
}
You can set the writing direction of a UITextView using the setBaseWritingDirection selector:
UITextView *someTextView = [[UITextView] alloc] init];
[someTextView setBaseWritingDirection:UITextWritingDirectionLeftToRight forRange:[someTextView textRangeFromPosition:[someTextView beginningOfDocument] toPosition:[someTextView endOfDocument]]];
The code is a little tricky because UITextView supports having different parts of the text with different writing directions. In my case, I used [someTextView textRangeFromPosition:[someTextView beginningOfDocument] toPosition:[someTextView endOfDocument]] to select the full text range of the UITextView. You can adjust that part if your needs are different.
You may also want to check whether the text in your UITextView is LTR to RTL. You can do that with this:
if ([someTextView baseWritingDirectionForPosition:[someTextView beginningOfDocument] inDirection:UITextStorageDirectionForward] == UITextWritingDirectionLeftToRight) {
// do something...
}
Note that I specified the start of the text using [someTextView beginningOfDocument] and searched forward using UITextStorageDirectionForward. Your needs might differ.
If you subclass UITextView replace all these code samples with "self" and not "someTextView", of course.
I recommend reading about the UITextInput protocol, to which UITextView conforms, at http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextInput_Protocol/Reference/Reference.html.
Warning about using the textAlignment property in iOS 5.1 or earlier: if you use it with this approach together with setting the base writing direction, you will have issues because RTL text when aligned left in a UITextView actually aligns to the right visually. Setting text with an RTL writing direction to align right will align it to the left of the UITextView.
Try textAlignment property.
textView.textAlignment = UITextAlignmentRight;
Take a look at UITextView Class Reference.
EDIT: Maybe CATextLayer can help you, someone suggests to use this class to customize text, but I've never used it personally...
Otherwise, you can force your textView to reverse your input in UITextFieldDelegate method:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
The text field calls this method whenever the user types a new character in the text field or deletes an existing character.
Here you can replace your input with a new NSString where you put the characters from right to left.
Hope this makes sense...
Ah... Do not forget to set
textView.textAlignment = UITextAlignmentRight;
to move your prompt on the right.
Try this code:
yourtextview.textAlignment = UITextAlignmentRight;
Hope this helps you.
Something which no one mentioned here or on any other post is that make sure you have not called sizeToFit for TextView. It simple aligns the textView (not text) to the left which gives the illusion that text is left to right instead of right to left.
If you are creating UI from Storyboard, the set constraint to Lead or Trailing space and value of First Item will be Respect Language Direction
in swift you can use this code
textView.makeTextWritingDirectionRightToLeft(true)

How to stop cells from indenting - shouldIndentWhileEditingRowAtIndexPath has no effect

I have a plain (not grouped) tableView with custom cells, and when I hit the Edit button, the cells indent. I don't want that, I want the deletion sign to lay right on top of my cell.
I tried shouldIndentWhileEditingRowAtIndexPath and also cell.shouldIndentWhileEditin = NO; as well as cell.indentionLevel = -3, but both won't have any effect. Any idea why?
Could this be due to my setup? I followed this tutorial, and I also tried a setup like Davyd suggested here, but the last did not only still indent my cells, it made it even worse, as the cells were indented, when I press Done.. and I can't get the background image to cover the whole cell...
So, anyone knows how to stop custom cells in a plain tableview from intending, while still showing the delete and move sign?
//EDIT:
btw, I build the custom cell in IB. I can take away the checkmark saying "Indent while Editing", it doesn't care. I can change the values for indention level and width, no effect. If i change the editing accessory, it happily displays it.
Hope that helps..
Thanks!
After a lot of research and trying pixel by pixel, it turned out, I needed to use -(void)layoutSubviews to "transit" from the original state to the original size.. If someone else ever needs to do that, here's my code, placed in my CustomCell.m:
- (void)willTransitionToState:(UITableViewCellStateMask)aState
{
[super willTransitionToState:aState];
self.state = aState;
}
- (void)layoutSubviews
{
[super layoutSubviews];
// no indent in edit mode
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
if (self.editing )
{
NSLog(#"subview");
float indentPoints = self.indentationLevel * self.indentationWidth;
switch (state) {
case 3:
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width +124,// - indentPoints,
self.contentView.frame.size.height);
break;
case 2:
// swipe action
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width +75,// - indentPoints,
self.contentView.frame.size.height);
break;
default:
// state == 1, hit edit button
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width +80,// - indentPoints,
self.contentView.frame.size.height);
break;
}
}
}
Hope that helps :)
None of the above works for me, but this did:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}
This way your saying to the UITableView that you dont want any native styling when in edit mode, and instead you can take care of it yourself.
Have you checked that the delegate method tableView:shouldIndentWhileEditingRowAtIndexPath: is being called when you edit the cell?
The only time I used the tableView:shouldIndentWhileEditingRowAtIndexPath: delegate method
it worked fine.
// Override to prevent indentation of cells in editing mode (in theory)
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
Try changing the autoresizing mask of your content view or the elements inside your cell. The indent is because when your cell enters editing mode the content view is resized to show the accessories and the content moves with it.
It's hard to give specific advice without knowing what's in your cell, but you want to look at the fixed left or right margins.
I had the same problem. The reason is: They're not indented but auto-resized. The remove button is shown an the cell's view (and its subviews) are resized.
Solution is: Set the autosizing behavior of the custom table cell's subviews (the labels or whatever you placed on it) in InterfaceBuilder/Xcode as you need it.
I just realized that if you connect a UIView to the backgroundView outlet, it doesn't move at all. That combined with autoresizing flags is really all you need, I think.
Just tried this on iOS 6.
The shouldIndentWhileEditingRowAtIndexPath delegate method now works on plain table view as well.
----Edited-----
Well, as it turned out, it doesn't indent only if allowsMultipleSelection = YES