Text of textview is overlapping under textview - ios

My question is simple and I think it is possible but I cant find it.
My design is like this
I give corner radius to textview and also set textContainerInset for padding from right and left both side
txtview_msg.textContainerInset = UIEdgeInsetsMake(5, 10, 10, 5)
Now my problem is like for first 2 line and last 2 line my text goes beneath textview so I need some solution for it.
Please help me into this. Thank you

try this code
UIView *paddingView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, txtview_msg.frame.size.height - 30)];
txtview_msg.leftView = paddingView1;
txtview_msg.leftViewMode = UITextFieldViewModeAlways;
UIView *paddingView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, txtview_msg.frame.size.height - 30)];
txtview_msg.leftView = paddingView2;
txtview_msg.rightViewMode = UITextFieldViewModeAlways;

You can create at first a view of same size how much you given, put cornerRadius how much you given in textview now. than create textview viewSize - corner radius. place the textview exactly in middle of view. set the constraints from that view only, than it will work perfect how you want.
check this attached screenshot:

Related

Can't centre UITextField in UIView

I'm trying to add my UITextField to a UIView that is placed in the centre of the table. The UIView works fine and is positioned correctly. however the UITextField is in the wrong position and at the bottom left of the screen. Code below:
self.addFriendView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
self.addFriendView.center=self.view.center;
[self.addFriendView setBackgroundColor:[UIColor whiteColor]];
UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 280, 40)];
nameField.delegate=self;
nameField.center=self.view.center;
nameField.placeholder=#"enter username";
[self.addFriendView addSubview:nameField];
[self.tableView.superview addSubview:self.addFriendView];
When I am placing the UITextField in the centre of the UIView do the coordinates need to be inside the UIView's coordinates or the frames?
That's because addFriendView.center is it's center in it's superview coordinate which is {150, 25}. What you want is that put the center of nameField in the center of addFriendView in addFriendView's coordinate.
So, use this:
nameField.center = CGPointMake(CGRectGetMidX(addFriendView.bounds),
CGRectGetMidY(addFriendView.bounds));
Updated to use CGRectGetMidX and CGRectGetMidY instead.
Because you have added nameField as a subview of self.addFriendView, its center will need to be relative to self.addFriendView.
nameField.center=self.view.center;
This line here is causing your issue. If fact, it's also an issue where you assign self.addFriendView's center, but by luck, self.view's bounds happen to be the same as its superview's.
Instead, you'll want to do this:
nameField.center=CGPointMake(CGRectGetMidX(self.addFriendView.bounds),
CGRectGetMidY(self.addFriendView.bounds));
and also, just for robustness:
self.addFriendView.center=CGPointMake(CGRectGetMidX(self.view.bounds),
CGRectGetMidY(self.view.bounds));

Programmatically create subview that covers the top 50% of the iPhone screen

I have a subview and I have been customizing its size by using the frame property and setting its value to the CGRectMake function's parameter values.
I have slowly but surely been changing the CGRectMake parameters and re-running the app to get the subview to the correct position on the screen but I know there has to be an easier way.
Here is what I am currently doing:
UIImageView *halfView = [[UIImageView alloc]initWithImage:image];
[self.view addSubview:halfView];
halfView.frame = CGRectMake(0, 0, 320, 270);
Is there a way that I can stop having to manually enter those 4 parameters into CGRectMake, and just set it to the top 50% of the screen?
Here is what I want the subview to look like on the iphone's screen:
halfView.frame = CGRectMake(0, 0, 320, self.view.bounds.size.height/2);
you just take the height and divide it by two
You should also probably change 320 to self.view.bounds.size.width
I suggest reading this post to really get a grasp of UIViews and working with them:
UIView frame, bounds and center

How to move element programmatically in iOS?

I have an element I have coded but I can't seem to get the code right so I can set the position of this on the screen. Here is my code:
- (void)setShowsRadar:(BOOL)showsRadar{
_showsRadar = showsRadar;
[_agController setShowsRadar:_showsRadar];
}
I want to position it like this:
initWithFrame:CGRectMake(5, 22, 60, 30)];
yourView.frame = CGRectMake(x,y,width,height);

How to remove dots in UITextfield?

In iOS, I am using one text field the length of the text field id too long so it is showing dots at the end of the text field. I need to remove the dots. I have used lineBreakMode also.
See the code I'm using.
CGSize maximumSize = CGSizeMake(titleListTxtFld.frame.size.width, 1000); //here 1000 for maximum height u can increase this if u want
CGSize strSize = [titleListTxtFld.text sizeWithFont:titleListTxtFld.font constrainedToSize:maximumSize lineBreakMode:UILineBreakModeClip];
CGRect newframe = CGRectMake(0, 0, strSize.width, strSize.height);
[titleListTxtFld.text drawInRect:newframe
withFont:titleListTxtFld.font
lineBreakMode:UILineBreakModeClip
alignment:UITextAlignmentLeft];
Please anyone help me on this.
Another approach is (Remove dot and clip text to frame)-
your can remove dot from UITextField calling following code
[self.yourTextField becomeFirstResponder];
you can also hide default keyboard [if you use any custom keyboard] using following code
// Hide keyboard for Dial Pad, but show blinking cursor
UIView *dummyKeyboardView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
yourTextField.inputView = dummyKeyboardView;
[dummyKeyboardView release];
But I think IlNero's answer is better for you if you want to show all text (does not clip).

Applying transform to UITextView - prevent content resizing

When I apply a rotation transform to a UITextView and then click inside to begin editing, it appears that the content size is automatically being made wider. The new width of the content view is the width of the rotated view's bounding box. For example, given a text box of width 500 and height 400, and rotated by 30 degrees, the new content width would be:
(500 * cos(30)) + (400 * sin(30)) = 633
Or graphically:
Interestingly, if you are already editing the text view and THEN apply the transform, then it appears that no modification is made to the content size. So it appears that sometime around the start of text editing, the text view looks at its frame property and adjusts the content size based on the frame width. I imagine the solution to this is to tell it to use the bounds property instead, however I don't know where to do this, as I'm not sure exactly where the text view is deciding to modify the content size.
I have googled but can't seem to find any references to using transformed UITextViews. Does anybody have any ideas about this?
EDIT (button action from test project):
- (IBAction)rotateButtonTapped:(id)sender {
if (CGAffineTransformIsIdentity(self.textView.transform)) {
self.textView.transform = CGAffineTransformMakeRotation(30.0 * M_PI / 180.0);
}
else {
self.textView.transform = CGAffineTransformIdentity;
}
NSLog(#"contentsize: %.0f, %.0f", textView.contentSize.width, textView.contentSize.height);
}
I was also stuck with this problem.
The only solution which I found was to create an instance of UIView and add the UITextView as a subview. Then you can rotate the instance of UIView and UITextView will work just fine.
UITextView *myTextView = [[UITextView alloc] init];
[myTextView setFrame:CGRectMake(0, 0, 100, 100)];
UIView *myRotateView = [[UIView alloc] init];
[myRotateView setFrame:CGRectMake(20, 20, 100, 100)];
[myRotateView setBackgroundColor:[UIColor clearColor]];
[myRotateView addSubview:myTextView];
myRotateView.transform = CGAffineTransformMakeRotation(0.8);
[[self view] addSubview:myRotateView];
Have you tried applying the rotation by doing a layer transform rather than a transform on the view?
#import <QuartzCore/QuartzCore.h>
mytextField.layer.transform = CATransform3DMakeRotation (angle, 0, 0, 1);
This might be enough to trick whatever broken logic exists inside the core text field code.

Resources