How to set UIView inside UITextView - ios

The below picture shows that there is a view Inside TextView. Now I want that Where UIView ends from there textview starts editing, not only from Left-top also from left-bottom.
How to do it ?
Is it possible ?
If Yes, then how ?
If no, then any other suggestion ?
In case of text filed below code is applied for left padding
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)];
textField.leftView = paddingView;
textField.leftViewMode = UITextFieldViewModeAlways;

You can wrap textfiled using below code
UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 30, 30)];
self.textView.textContainer.exclusionPaths = #[imgRect];
And, now you can add any control in place of "imgRect"
UIView *spacerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
spacerView1.backgroundColor = [UIColor redColor];
[textView addSubview:spacerView1];

Related

User can't able to enter amount before currency symbol in textfield in objective c

Below is an image of the screen, I just want to when the user enters the amount on this textfield then the user can't able to move cursor before $ sign and can't able to write amount before $ sign.
Please have a look on my problem, and give me idea about it,
You can simply add a textfield inside a view and before textfield add a lable with text "$". Remove the textfield border and add a border layer for view. It will work perfectly as per your requirement.
Try to set currency image as leftview of textfield
For Imageview
UIImageView *imageArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"currency.png"] ];
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[paddingView addSubview:imageArrow];
imageArrow.center = paddingView.center;
textfield.leftView = paddingView;
textfield.leftViewMode = UITextFieldViewModeAlways;
For Label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
label.text = #"$";
textField.leftViewMode = UITextFieldViewModeAlways;
textField.rightView = label;
You can use left view property of UITextField
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
label.text = #"$";
label.backgroundColor = [UIColor white];
textField.leftViewMode = UITextFieldViewModeAlways;
textField.rightView = label;

I am trying to create multiple UIView without for loop how to do it programmatically

I am trying this for creating multiple UIView without for loop
Code:
view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 50, 40)];
view = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 50, 40)];
view = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 50, 40)];
Here is the example to create a UIView programmatically
UIView *popup=[[UIView alloc]init];
popup.frame=CGRectMake(0,0, self.view.frame.size.width/2, self.view.frame.size.height/3);
popup.center = self.view.center;
popup.backgroundColor=[UIColor orangeColor];
[self.view addSubview:popup];
You can change X,Y,Width,Height as per you requirement.

UITextField "content size" property

Is there a way to make the right side of a UITextField's content "end sooner" like in this graphic:
I'm using the following to give the content text some left padding, but can't figure out an easy solution to reduce the available content size on the right size: self.textfield.layer.sublayerTransform = CATransform3DMakeTranslation(10, 0, 0);
I'd rather not subclass UITextField but I'm fine doing so if need be.
try these...
i hope it helps..
UITextField *txt=[[UITextField alloc]initWithFrame:CGRectMake(10, 100, 150, 30)];
[txt setBackgroundColor:[UIColor lightGrayColor]];
[txt setPlaceholder:#"Hello my friend"];
[self.view addSubview:txt];
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 50, 30)];
txt.rightView = paddingView;
txt.rightViewMode = UITextFieldViewModeAlways;

Trouble pressing button using CALayer

I have a button (iOS) that has the mask set for its CALayer:
self.aButton.layer.backgroundColor = [UIColor redColor].CGColor;
button.layer.masksToBounds = YES;
then later the bounds are defined much smaller than the button area (button size about 50x50pts).
button.layer.bounds = CGRectMake(0, 0, 29, 29);
Now the button can only be clicked on inside the layer area. What is the simplest way to allow the entire button area (50x50pts) to still be clickable?
mask the layer of a UIView, add it as a subview to the button.
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 29, 29)];
redView.layer.backgroundColor = [UIColor redColor].CGColor;
UIButton *aButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
redView.center = aButton.center;
redView.userInteractionEnabled = NO;
[aButton addSubview:redView];
Or as a sublayer
CALayer *layer = [[CALayer alloc] init];
layer.backgroundColor = [UIColor redColor].CGColor;
layer.frame = CGRectMake(10.5, 10.5, 29, 29);
UIButton *aButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[aButton.layer addSublayer:layer];

How do I add Two UILabels in my UIScrollView for the iphone?

myscrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];
myscrollview.delegate = self;
[self.view addSubview:myscrollview];
CGSize scrollViewContentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+500);
[myscrollview setContentSize:scrollViewContentSize];
lblluckyno = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 200, 50)];
lblfirstmsg = [[UILabel alloc] initWithFrame:CGRectMake(15, 50, 295, 800)];
But I don't know My Firstmasg length.... after that lblfirstmsg I want to add second lblsecongmgs.... So how can I add?
After you set first label and set it content you can call [lblfirstmsg sizeToFit]; to fit frame to its content. Then you can add your second UIlabel next to the first one [[UILabel alloc] initWithFrame:CGRectMake(lblfirstmsg.frame.origin.x + lblfirstmsg.frame.size.width, lblfirstmsg.frame.origin.y, 200, 50)];
[myscrollview addSUbview:lblluckyno];
and same way add 2nd label.
This is your scroll view code.
myscrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];
myscrollview.delegate = self;
[self.view addSubview:myscrollview];
[myscrollview setContentSize:CGSizeMake(self.view.frame.size.width,self.view.frame.size.height+500);];
After you set two label With CGRect and add in Scroll View
[myScrollView addSubView:lblluckyno];
......
Hello Mayur P Bhansali,
You can find the position and dimension of your first label like so:
lblluckyno = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 200, 50)];
UILabel *secondLabel = [[UILabel alloc] initWithFrame: CGRectMake(lblluckyno.frame.origin.x + lblluckyno.frame.size.width, 200, 100)];
Each UIView has a "frame" object and this frame object has a "origin" C structure and "size" C structure. Using labelName.frame.size.width gives you the width of a frame and labelName.frame.origin.x gives you the X coordinate of the frame.
You could access these properties like this too:
[labelName frame].size.width
[labelName frame].size.origin.x
lblluckyno = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 200, 50)];
lblfirstmsg = [[UILabel alloc] initWithFrame:CGRectMake(15, 50, 295, 800)];
[myscrollview addSUbview:lblluckyno];
[myscrollview addSUbview:lblfirstmsg];

Resources