iOS 7 SegmentControl Background Color - ios

Picture says it all (see arrows). Any way I can make sure the background is transparent? If I set the background to transparent on the UISegmentedControl it sets the button color to transparent too, but we want to avoid this.
Clarification: We want to keep the buttons white, but get rid of the white stuff in the corners. Setting background to white does this but then makes the buton background transparent too, which we don't want.
Update: Now looks as follows, after trying Astri's suggestion and setting corner radius to 5. Still, there is a white space on the right.

After the clarification:
Try this:
yourSegmententControl.layer.cornerRadius = 5;
Make sure you import Quartz

I experienced the same white space on the right problem when I explicitly set the width of the UISegmentedControl.
To fix it, do not set the width of the segmented control – just set the width of each segment instead.
// Determine your segment width
CGFloat segmentWidth = 50.0;
// Loop through the segments
for (NSInteger i=0; i<mySegmentedControl.numberOfSegments; i++) {
// Set the width of each segment
[mySegmentedControl setWidth:segmentWidth forSegmentAtIndex:i];
}

The background colors of the views of the controlls are already transparent, so you need to set them too to whatever color you want, not just the background color of the view of the segmented controll. Keep in mind that the controlls have different configurations for their state.

Related

how to make visible other components in transparent UIVIEW in swift 5

I have used a UIVIEW . I want to make transparent the UIVIEW. But when I want to chage alpha 0.0 from storyboard for make UIVIEW transparent, textfield, label and other component also transparent. I want to make transparent UIVIEW, not other component of the view. Here is the image
Please help me to make visible other components in UIVIEW transparent
Set your UIView's backgroundColor to UIColor.clear.
Instead of changing the alpha of the UIView, you can make the background color of your UIView as white with alpha component 0.5 or something
myView.backgroundColor = UIColor.black.withAlphaComponent(0.5)
If you want it to be completely transparent, you can set backgroundColor to clear from storyboard as well as code.
myView.backgroundColor = .clear
You just need to change the transparency not of the UIView itself, but of its
background color.
For example:
I set the color of the UIView transparent, while the UILabel remained its settings.
In order to create a semi transparent color, you can use the following code:
yourView.backgroundColor = UIColor.white.withAlphaComponent(0.5)
Hope this will help you!
Go to Main.Storyboard and select the view you want to make transparent.
From the Attribute Inspector select background color as custom.
Then set your desired color and decrease the percentage of Opacity of the color.

Working with transparency: View behind transparent view should only shine through and not overlap

I'm currently working with transparency and I'd like to have the following effect:
As you can see the line takes the full width of the view. There are some transparent UIViews also on this screen. The line seems to be below the transparent UIView and if it overlaps it has another color, because of the transparent UIView above. When there is no overlapping the line get its normal color.
How can I get this effect?
I tried to set the background of the UIView to transparent, but it didn't helped. The line has its normal color and doesn't interact with the transparency. Furthermore I tried to change the transparency of the view itself but with the same wrong result.
The rectangle above is done with code
UIView rectangle = new UIView (new CGRect (10, 10, 200, 120));
rectangle.BackgroundColor = UIColor.FromRGBA (204,115,225, 50);
UIView line = new UIView (new CGRect (0, 105, 320, 1));
line.BackgroundColor = UIColor.Red;
View.AddSubview (line);
View.AddSubview (rectangle);
line.SendSubviewToBack (rectangle);
the rectangle below is created in iOS designer.
Am I missing something?
Its all about the z order of the Subviews.
line.SendSubviewToBack (rectangle);
is probably not what you want.
If you add the line with its normal red color and add a UIView that has its alpha dropped to e.g. 0.5, then you should get the effect you want.
The z-order of the subviews was correct in my case. Depending on the color the effect I want is possible or not. So I made the following:
Choose another background color for the lavender color rectangles and adapt the alpha transparency to look similar. So something like this:
rectangle.BackgroundColor = UIColor.FromRGBA (245/255.0f,227/255.0f,249/255.0f,0.7f);

how to get the default style of uinavigationbar for a uiview

I am trying to make an uiview look just like the default uinavigationbar in ios 8.
I don't want to hardcode the values so would like to take the uinavigationbar color, height , width and the border at the bottom and apply the same to a custom uiview.
Is there any way I can achieve it ?
self.headerBar.backgroundColor = self.navigationController.navigationBar.backgroundColor;
I tried the above but it didn't work.
K I finally had to combine the following
[UIColor colorWithRed:(247/255.0) green:(247/255.0) blue:(247/255.0) alpha:1];
for the uiview colour than had to put in another uiview that i added as a subview to the original view with small height so that it looks like a border and gave it colour dark gray and alpha 0.4f. One thing to note here is that the border can also be created using layer but that by default doens't take care of orientation changes.
As for height width just gave the height width as per the superviews bounds to which this custom navigation bar is to be attached.
Well you can use UIToolBar and set its properties accordingly as in UINavigationBar, like tintColor, barTintColor, translucent, etc..
Note: UIToolBar inherits from UIView
If you are using UIView and want to get the navigation bar color then its the barTintColor property you should use and not the backgroundColor
self.headerBar.backgroundColor = self.navigationController.navigationBar.barTintColor;

View controller with background image and transparency xamarin

I kind of stuck with a design issue in iOS.
I have a controller with a background image, nothing special.
this.View.BackgroundColor = UIColor.FromPatternImage (UIImage.FromFile ("Images/ballons.jpg"));
On top of the controller I have a view with a background color (white) that is semi-transparent.
this.Frame = new System.Drawing.RectangleF (0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
this.BackgroundColor = UIColor.White;
this.Alpha = 0.5f;
Now the issue is if I add a button or any other controls in my view they also becomes transparent...so am I thinking wrong here...?
I would like the controller to have a background image, the view a white semi-transparent background and all the controls (buttons, images) not to be transparent at all...
Do not change the Alpha of the view, since that will change the transparency of all its elements/subviews. Just set its BackgroundColor to a semi-transparent color using UIColor.FromWhiteAlpha(1, 0.5).

UINavigationBar with shaped background

I'm trying to make a custom UINavigationBar, but the problem is that my background image has a curve in it, and its little bit larger than default navigation bar. When I try to set background image and change navigation bar size, its just scales image as a rectangle. Any ideas?
Bar:
Override
- (CGSize) sizeThatFits:(CGSize)size {
return CGSizeMake(custom_width, custom_height);
}
in order to return the size for your custom navigation bar.
Note that if you use a height that is not a multiple of 4, it will cause trouble if you hide and then show the navigation bar at any point (it gets shifted by 1 pixel from the top)

Resources