I'm currently in the process of making my custom tab bar. It's working fine, the way I did it was by hiding the default bar. I have my images prepared, the on and off ones.
There seems to be an implementing of these into the main concept by using:
btn3.frame = CGRectMake(240, 430, 80, 50);
The number combination is unique for each CGRectMake. I have done it, but i'm using 3 buttons on the bar. This tutorial uses four. What should I set the number combination for each CGRectMake if i'm using 3 buttons and not 4. Because I assume that the combos are proportional to each other depending on how many tabs there are. All it is, is setting the frame size and position of the button/tab.
I used these for my tabs, but I got a gap in between.
btn1.frame = CGRectMake(0, 430, 80, 50);
btn2.frame = CGRectMake(160, 430, 80, 50);
btn3.frame = CGRectMake(240, 430, 80, 50);
http://www.rumexit.co.uk/2010/11/how-to-customise-the-tab-bar-uitabbar-in-an-iphone-application-part-2-of-2/
it's in the fourth box on the page.
// Pseudocode.
int numButtons = 3;
float buttonWidth = self.view.frame.size.width / numButtons;
btn1.frame = CGRectMake(0 * buttonWidth, 430, buttonWidth, 50); btn2.frame = CGRectMake(1 * buttonWidth, 430, buttonWidth, 50); btn3.frame = CGRectMake(2 * buttonWidth, 430, buttonWidth, 50);
Related
Recently i tried to create a custom segmentedControl where i had three views in it.
WHILE I WAS TOUCHING FIRST HALF OF THE VIEW THE tapGesture WORKED. But the rest half dint respond.
My frame of the segment is:
segment.frame=CGRectMake(0, 0, 300, 100) ;
And the frame of the UIView is:
view1 = [[UIView alloc]initWithFrame:CGRectMake(10, 80, 100, 40)];
change the height of the frame to 200 And then it will work:
segment.frame=CGRectMake(0, 0, 300, 200) ;
Reason: Your height of the view is less when compared.
Put Your view frame like this it will work for you..Because you add Segment with height 100 from y=0, So you can set view frame after y = 100..
view1 = [[UIView alloc]initWithFrame:CGRectMake(10, 110, 100, 40)];
Am working in an iPhone app using UITextView. I am trying to increase the height of UITextView based on it's content length. It is working fine. But, when the height of uitextview increase the UITextView should change the height in up side not increase height in down.
This is the code am trying in my project,
baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 50)];
baseView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:baseView];
TextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, 280, 40)];
TextView.backgroundColor = [UIColor whiteColor];
TextView.layer.borderWidth = 2;
TextView.delegate = self;
TextView.font = [UIFont fontWithName:#"Helvetica" size:16];
[baseView addSubview: TextView];
-(void)textViewDidChange:(UITextView *)textView
{
CGRect frame = messageTextView.frame;
frame.size.height = messageTextView.contentSize.height;
TextView.frame = CGRectMake(20, 10, 280, frame.size.height);
baseView.frame = CGRectMake(0, 50, 320, frame.size.height+20);
}
When the UITextView height is changing the effect textview height will be increase on top side. Can anyone please help me on this? Thanks in advance.
In the method you change the frames, also edit the frame.origin.y value of the textView
-(void)textViewDidChange:(UITextView *)textView
{
CGRect frame = messageTextView.frame;
frame.size.height = messageTextView.contentSize.height;
TextView.frame = CGRectMake(20, 0, 280, frame.size.height); //previous y was 10
baseView.frame = CGRectMake(0, 50, 320, frame.size.height+20);
}
Nonetheless, I believe you are aware that you have only 10 pixels for the textView to go up, as you are adding it to a BaseView view.
I would like to change the color of the clearButton that appaers when you are writting on a UItextField. Any suggestion? I am not an advanced interface developer and I have no idea of how to do it.
You should create your own UIButton (with image, you'll need a png of you desiderated button), instance it and put this button in the rightView of your UITextField.
CGFloat myWidth = 26.0f;
CGFloat myHeight = 30.0f;
UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, myWidth, myHeight)];
[myButton setImage:[UIImage imageNamed:#"myButtonImage"] forState:UIControlStateNormal];
[myButton setImage:[UIImage imageNamed:#"myButtonImage"] forState:UIControlStateHighlighted];
[myButton addTarget:self action:#selector(doClear:) forControlEvents:UIControlEventTouchUpInside];
myTextField.rightView = myButton;
myTextField.rightViewMode = UITextFieldViewModeUnlessEditing;
You could need to refine alignments using (these are example values):
myButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
Then, you will need to implement method -(void) doClear(id)sender; that will clear your textfield.
Swift 4
I used Giorgio's answer and this is what I went with :
let height = textField.bounds.height / 3
let width = height + 10
let rect = CGRect(x: 0, y: 0, width: width, height: height)
let myButton = UIButton(frame: rect)
myButton.setImage(UIImage(named: "clear button white"), for: .normal)
textField.rightView = myButton
textField.rightViewMode = .always
myButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
The normal one :
enter image description here
This one :
enter image description here
I am trying something like below
UIView * view = [UIView new];
view.frame = CGRectMake(50, 50, 200, 200);
view.bounds = CGRectMake(0, 0, 400, 400);
view.backgroundColor = [UIColor grayColor];
UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(50, 50, 300, 50)];
[btn setTitle:#"Button" forState:UIControlStateNormal];
[view addSubview:btn];
CALayer * layer = [view layer];
[layer drawInContext:ctx];
My questions is
1) Like we draw images or text with CGContextRef , can we draw a UIView instance the same way ?
I am not so familliar with the core graphics framework , so please let me know the possibilities . My basic aim is to be able to draw custom views in drawRect using CGContextRef by any means .
Thank you in advance !!!
You have to implement -(void)drawRect:(CGRect)rect method in your subclass of UIView. In this method you should draw to the current context.
I have a UIToolbar in which I have placed a UIProgressView successfully. However, I have seen some apps contain a small label above the UIProgressView which tells the user what the program is doing where progress is being made -- e.g. to download a file. However it seems that this cannot be done in UI Builder. Any ideas on the best way to add the label ablve the UIProgressView in the toolbar? Here is what I am interested in:
+------------------------------------------------+
| Uploading File |
| ================-------------------- [CANCEL] |
+------------------------------------------------+
Make a custom UIView that contains a UILabel and UIProgressView as subviews. You then insert the custom UIView into the toolbar.
You can actually also add text directly to a UIProgressView as a subview, ex:
UIProgressView *videoProgressView = [[UIProgressView alloc] initWithFrame:CGRectMake(40, self.view.frame.size.height/2, self.view.frame.size.width - 80, 40)];
UILabel *processing = [[UILabel alloc] initWithFrame:CGRectMake(0, -50, videoProgressView.frame.size.width, 25)];
processing.text = #"Processing Video...";
processing.textAlignment = NSTextAlignmentCenter;
[videoProgressView addSubview:processing];
[self.view addSubview:videoProgressView];
Just make sure UIProgressView's clipsToBounds property is set to NO.
Here's a Swift 5 implementation of Lyndsey Scott's answer used in my project:
let view = UIApplication.topViewController()!.view!
let progressView = UIProgressView(progressViewStyle: .default)
progressView.center = view.center
progressView.trackTintColor = .gray
progressView.frame = CGRect(x: 40, y: view.frame.size.height / 2, width: view.frame.size.width - 80, height: 40)
let progressViewLabel = UILabel(frame: CGRect(x: 0, y: -50, width: progressView.frame.size.width, height: 25))
progressViewLabel.text = "Migrating database:"
progressViewLabel.textAlignment = .center
progressView.addSubview(progressViewLabel)
view.addSubview(progressView)