In our project we wanted to change the size of navigationbar. Have achieved it with
#implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size {
return CGSizeMake(self.superview.bounds.size.width, 55.0f);
}
#end
But the problem here is.. as you would see go button is little down from screen edge. But I wanted it to be in ultimate corner of screen. I use backgroundColor:, setTitle:forState:methods for constructing look of go button. also back button to be vertically middle. How can I achieve that. Tried Using edgeInsets: but no hope.
Edit: Go button height is 10px less than barheight.
if I give equal height. Below is the result
in somewhat I have tried your coding.Check that
UIButton *goBtn = [UIButton buttonWithType:UIButtonTypeCustom];
goBtn.frame = CGRectMake(0, 0, 63, 80);
goBtn.backgroundColor = [UIColor redColor];
UIView *goButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 63, 50)];
NSLog(#"goButtonView bounds are - %#", NSStringFromCGRect([goButtonView bounds]));
goButtonView.bounds = CGRectOffset(goButtonView.bounds, -17, 0);
NSLog(#"goButtonView bounds are - %#", NSStringFromCGRect([goButtonView bounds]));
[goButtonView addSubview:goBtn];
UIBarButtonItem *goButton = [[UIBarButtonItem alloc] initWithCustomView:goButtonView];
self.navigationItem.rightBarButtonItem = goButton;
Below the references
Issue with button on the left side of the uinavigation bar
UINavigationBar UIBarButtonItems much larger click area than required
Related
I am trying to move a custom notification badge with the following code. The badge only can go up or down. I am not able to move it left or right. profileBadge is custom UIView. I add the custom badge UIView to an UIButton and then i move it up by -4.0 in y axis. I try to move it to the left using -8.0 in x axis using CGRectFrame but does not move. The UIButton with the badge UIView is added in the top navigation bar.
profileBadge= [[BadgeView alloc] initWithFrame:CGRectMake(0, 0, 14.0, 14.0)];
profileBadge.font = badgeFont;
profileBadge.horizontalAlignment = M13BadgeViewHorizontalAlignmentRight;
profileBadge.verticalAlignment = M13BadgeViewVerticalAlignmentNone;
profileBadge.badgeBackgroundColor = [UIColor redColor];
profileBadge.text = #"";
profileBadge.hidden = YES;
[profileBadge setFrame:CGRectMake(-8.0, -4.0, 14.0, 14.0)];
[profileBadge.superview bringSubviewToFront:profileBadge];
Button.contentEdgeInsets = UIEdgeInsetsMake(0, 14, 0, 8);
[Button addSubview:profileBadge];
I tried using also using profileBadge.layoutMargins but does not move left or right. Any help apprecitated.
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'm creating a simple button and adding it as a subview to main view. It doesn't show up though.
This is the code for setting it up:
UIButton* contactButton = [[UIButton alloc] init];
contactButton.titleLabel.text = #"Contact Developer";
[contactButton sizeToFit];
[self.view addSubview:contactButton];
NSLog(#"X: %f || Y: %f || Width: %f || Height: %f", contactButton.frame.origin.x, contactButton.frame.origin.y, contactButton.frame.size.width, contactButton.frame.size.height);
As you may have noticed, I placed a bit of debug code at the end to see the position and dimensions of the button. They are: X: 0, Y: 0, Width: 30, Height: 34
This means it should be showing up in the upper left corner but it doesn't. Whats wrong?
One possible reason for this is that you used titleLabeldirectly. Consider using setTitle:forState: method instead.
To be sure, consider setting backgroundColor, as a debug step, to make sure it's appearing.
Edit As others suggested, try using buttonWithType: instead of [[UIButton alloc] init]. I suggest using UIButtonTypeSystem instead of UIButtonTypeCustom.
You should initialise the button using the following:
UIButton* contactButton = [UIButton buttonWithType:UIButtonTypeCustom];
Try constructing your button a different way:
UIButton* contactButton = [UIButton buttonWithType:UIButtonTypeCustom];
contactButton.backgroundColor = [UIColor redColor];
contactButton.titleLabel.text = #"Contact Developer";
[contactButton sizeToFit];
[self.view addSubview:contactButton];
Are you sure that the button it's not being shown?
I think you are setting the title of the button incorrectly and because of the fact that a default UIButton has clear background and white title, it´s not visible if your superview is white too.
Instead of setting:
contactButton.titleLabel.text = #"Contact Developer"
use:
[contactButton setTitle:#"Contact Developer" forState:UIControlStateNormal]
But you can first try to set a backgroundColor to the button, different that the superview, to see if it's added.
Hope it helps!
(Sorry for my english if i have a mistake)
I'm trying to create modalviewcontroller, which should look like this
My problem is in the close button. As you can see in this example it almost out of uiview.
I was tried uiview, who has close button, make transparent but when modalview opens it's still in light gray color.
There is bit of my code :
Settings *new = [[Settings alloc]init];
new.modalPresentationStyle = UIModalPresentationFormSheet;
//i was change to other presentation styles, but that no I want.
new.view.backgroundColor = [UIColor clearColor];
[self presentModalViewController:new animated:YES];
CGRect r = CGRectMake(self.view.center.x - 327,
self.view.center.y - 255,
630, 490);
r = [self.view convertRect:r toView:new.view.superview.superview];
new.view.superview.frame = r;
If you still don't understand, what I want there is ilustration of modal view I need:
What is your suggestion, how can I make it?
I'm trying to have a custom titleView for Iphone app iOS 5.0+ . So I placed a graphic like this :
UIView *customTitleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 104, 72)];
UIImageView *customTitleGraphics = [[UIImageView alloc] initWithImage:image];
[customTitleGraphics setTag:kNavigationImageView];
CGRect myFrame = customTitleGraphics.frame;
myFrame.origin.y = 15.0;
myFrame.origin.x = -3.0;
customTitleGraphics.frame = myFrame;
[customTitleView addSubview:customTitleGraphics];
navigationItem.titleView = customTitleView;
And It works so far. The problem i Have is when I try to push another viewController: It looks like the titleView get cut off suddenly when the animation starts.
https://www.dropbox.com/s/0ysiroxayfld1l3/titleview.mov?v=1mci
Do you have any idea where I'm wrong?
I think that the title view is resized by the UINavigationBar when you push the new VC to the navigation stack. What I would suggest would be to prevent the navigation view from clipping to bounds…