New to iOS.Learning iOS swift by blogs and online materials. I want to create login form which looks like below. Importantly icon before textfield. How can I achieve that ? Please suggest
And how can i add logo on whitespace top? do i need to add bar item and add picture/logo?
You can achieve in swift like below :
let leftImageView = UIImageView()
leftImageView.image = leftImage
let leftView = UIView()
leftView.addSubview(leftImageView)
leftView.frame = CGRectMake(0, 0, 30, 20)
leftImageView.frame = CGRectMake(0, 0, 15, 20)
textField.leftView = leftView
For Objective C try something like this
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 26, 26)];
imgView.image = [UIImage imageNamed:#"img.png"];
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
[paddingView addSubview:imgView];
[txtField setLeftViewMode:UITextFieldViewModeAlways];
[txtField setLeftView:paddingView];
From my understanding of your question, What i would suggest is the icon images you want to have on your interface. Open up the folder that has the xcode project in it. Click the top folder the one above the xcode project click assets. You know you are in the right folder when you get to the folder that has appicon folder in it. Put the images there. Then pull up your project next to the folder and dragg the items into your xcode project under the tab that says main storyboard then click the blue button in the bottom righthand corner now search your object library for image view drag that onto your interface then click the attributes inspector then about the top drop down add the image that you added before. Hope this helps.
you can create a nib with your image.
for example
let customNavBarView = NSBundle.mainBundle().loadNibNamed("SomeXibView", owner: self, options: nil)?.first as! UIView
self.navigationController?.navigationBar.inputView = customNavBarView
so far I've done this with mine and it works
Related
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:
I don't know if this is a bug or what but I can't understand why it happens.
I have 2 UITextField that once clicked show the users an UIPickerView, everything was working fine until I tried to add a custom arrow image in order to let the user know about the dropdown. this is the code I've used in order to create the rightView:
UIImageView *arrowDown = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"p-dropdown"]];
arrowDown.frame = CGRectMake(0, 0, 26, 22);
_province.rightViewMode = UITextFieldViewModeAlways;
_province.rightView = arrowDown;
_address.rightViewMode = UITextFieldViewModeAlways;
_address.rightView = arrowDown;
As soon as the last line ends the app freezes and it starts using like 20MB/s of RAM without stopping, I tried to comment all the code above and the problem doesn't occur, the funny thing is that if I comment just one of the two rightView ,so something like this:
UIImageView *arrowDown = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"p-dropdown"]];
arrowDown.frame = CGRectMake(0, 0, 26, 22);
_province.rightViewMode = UITextFieldViewModeAlways;
_province.rightView = arrowDown;
I can correctly see the rightView and the app doesn't freeze. Can someone help me to understand what is causing this weird issue?
One instance of UIView can't be utilized as right view of multiple UITextFields. You have to make two instances of your UIImageView to make your app work as expected. As you yourself found out, that one view cant be displayed on a screen multiple times simultaneously.
I am under one project.In that I created one uibutton at bottom of my viewcontroller using code (Not via storyboard).But when i run my app,my uibutton are placing in differents positions.for example in iphone 5,6 simulator are in some position.In 4s,ipad simulator my uibutton is unvisible.Also i check with my own device(iphone 6) ,in that also my uibutton is not able to see.
Needed
I used below code for creating & placing my button position.but its not fit in one position.
CGFloat buttonSize = 40;
UIButton * disButton = [[UIButton alloc] init];
disButton.backgroundColor = [UIColor redColor];
UIImage *btnImage = [UIImage imageNamed:#"23"];
[disButton setImage:btnImage forState:UIControlStateNormal];
disButton.frame = CGRectMake(150, 523, 40, 40);
[overlayView addSubview:disButton];
[disButton addTarget:self action:#selector(dismissPopUpViewController)
forControlEvents:UIControlEventTouchUpInside];
In my code i use to place position in this line:
disButton.frame = CGRectMake(150, 523, 40, 40);
=> x-position = 150
=> Y-position = 523
Kindly please give some code solution for this problem.
As per all comments about your question.You need to set constraint for your UIButon.Use only centre x,centre y because that will helpfull to see your layout in all devices. And there is a already solution for your problem.see these below links for setting auto layout for UIButton
Link 1
Link 2
Link 3
Sure this will help you !
i'm building custom keyboard for ios 8, so i want to display one image here but it's seems not work.
I really don't know why, here is my code:
var img = UIImageView()
img.frame = CGRectMake(0, 0, 50, 50)
img.image = UIImage(named: "interesting.jpg")
self.view.addSubview(img)
Nothing appear but if i change to display an UILabel, it's ok.
When i move this code to ViewController image display fine.
I couldn't display image in keyboard area only.
I think you could do this: UIImage(named: "interesting") and have the name of the image in the asset catalog be interesting
_topBar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 45)];
UIImageView *bar = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"top_bar.png"]];
bar.frame = CGRectMake(0, 0, 320, 45);
[_topBar addSubview:bar];
_up = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"up.png"]];
[_topBar addSubview:_up];
_up does not show up in my build. If i exchange the "up.png" for any other image in my resources folder, it shows up, but up.png refuses to. Is there anything I can do? I've initialized it using just a UIImage, a statically allocated UIImageView, removed and re-added the .png files, took them out of the resources folder and put them somewhere else, re-saved them, everything aside from throwing them out.
EDIT:
The file was saved as up.png but was really up.png.psd. just a matter of reading the fine print.
Check the Kind in Finder. Its probably not a png and therefore wouldn't display.
I now know this to be true since you commented :)
A couple of things. Select the file in the right pane, open the rightmost (3rd) file inspector pane, and insure that this image is included in your Target.
In code, break out this:
UIImage *image = [UIImage imageNamed:#"up.png"];
NSLog(#"image %#", image);
_up = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"up.png"]];
NSLog(#"UP FRAME: %#", NSStringFromCGRect(_up.frame) );
// maybe set the frame to what you want?
_up.frame = (CGRect){ {0,0}, image.size }; // set origin where you want it