Add padding to the right of the down arrow in a picker in ios renderer - xamarin

I am adding a down arrow to the xamarin picker. I created a custom iOS renderer for this. I can get the arrow to show up fine, but it is touching the right hand side of the picker. How can I add some padding to the right of the arrow? I have tried the following in my ios renderer.
protected void UpdateBackground(UITextField control)
{
if (control == null) return;
control.Layer.CornerRadius = ElementV2.CornerRadius;
control.Layer.BorderWidth = ElementV2.BorderThickness;
control.Layer.BorderColor = ElementV2.BorderColor.ToCGColor();
var downArrowLabel = new UILabel(new CoreGraphics.CGRect(new CoreGraphics.CGPoint(control.Frame.Size.Width - 20 - 16, 0), new CoreGraphics.CGSize(20, control.Frame.Size.Height)));
downArrowLabel.Font = UIFont.FromName("FontAwesome", 30);
downArrowLabel.Text = "\uf0d7";
downArrowLabel.TextColor = UIColor.Black;
downArrowLabel.TextAlignment = UITextAlignment.Center;
downArrowLabel.ContentMode = UIViewContentMode.ScaleAspectFit;
control.RightView = downArrowLabel;
control.RightViewMode = UITextFieldViewMode.Always;
control.RightView.Bounds = new CoreGraphics.CGRect(0, 0, 20 + 16, control.Frame.Size.Height);
}

I wrote a Picker renderer based on your code and tested it. I found that adding a few spaces after the Text can effectively solve this problem. It looks strange, but it works, like this
downArrowLabel.Text = "\uf0d7 ";

Related

How to display UIDatePicker to choose date

I am following this documentation so that I can pick a date in my Xamarin.iOS app like in this image:
https://learn.microsoft.com/en-us/xamarin/ios/user-interface/controls/picker-images/image9.png
But I can't get it to work. My code:
var datePickerView = new UIDatePicker();
datePickerView.MinimumDate = (NSDate)DateTime.Today.AddDays(-7);
datePickerView.MaximumDate = NSDate.Now;
datePickerView.Mode = UIDatePickerMode.Date;
datePickerView.Locale = NSLocale.FromLocaleIdentifier("en_US");
datePickerView.MoveAndResizeFrame(
UIScreen.MainScreen.Bounds.X - UIScreen.MainScreen.Bounds.Width,
UIScreen.MainScreen.Bounds.Height - 230,
UIScreen.MainScreen.Bounds.Width,
180
);
// Add(datePickerView); do I add it to my view?
I also tried making it my InputView of a UITextField but I get an ugly dialog that's not even usable like this.
var t = new UITextField();
t.InputView = datePickerView;
t.ResizeFrame(300, 50);
t.Placeholder = "enter date";
t.TextColor = UIColor.Black;
Add(t);
I am running this app on iPad with iOS 14.5
The problem is related with the position(frame) you set on the datepicker,the view would locate beyond of the screen in that scenario .
Use the following code , it works fine on my side .
Click on the label , then display the datepicker menu.
var datePickerView = new UIDatePicker();
datePickerView.MinimumDate = (NSDate)DateTime.Today.AddDays(-7);
datePickerView.MaximumDate = NSDate.Now;
datePickerView.Mode = UIDatePickerMode.Date;
datePickerView.Locale = NSLocale.FromLocaleIdentifier("en_US");
datePickerView.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 180); //this line
Add(datePickerView);

Slider background in Unity

First I made a picture of my problem:
http://imgur.com/a/D8oOj
You have 3 sliders and they all need a background color. Maybe the 3 labels below need a background color too.
GUI.color = Color.white;
Does not seem to help much. I need this black background for the simulation so i need to make the slider background white...
But GUILayout and GUISkin do not have properties for this, no? I can not find something useful there...
The components i use:
GUI.HorizontalSlider + GUI.Label
Within a GUI Skin, there is a Horizontal Slider property. That property has GUI Style properties of Normal, Hover, Active, and Focused. You should set a background to all 4 of those elements.
Here's an example using programmatically-created GUIStyle (tested with Unity 5.4.2p4). Note that when creating a fresh GUIStyle, you need to assign dimensions, or it might not be visible.
public class MySliderIMGUI : MonoBehaviour
{
private GUIStyle _sliderBackgroundStyle;
private GUIStyle _sliderThumbStyle;
private float _sliderValue = 0f;
private Texture2D _whitePixel;
private Texture2D _blackPixel;
void Start()
{
this._whitePixel = new Texture2D(1, 1, TextureFormat.ARGB32, false);
this._whitePixel.SetPixel(0, 0, Color.white);
this._whitePixel.Apply();
this._blackPixel = new Texture2D(1, 1, TextureFormat.ARGB32, false);
this._blackPixel.SetPixel(0, 0, Color.black);
this._blackPixel.Apply();
this._sliderBackgroundStyle = new GUIStyle();
this._sliderBackgroundStyle.padding = new RectOffset(2, 2, 2, 2);
this._sliderBackgroundStyle.normal.background = this._whitePixel;
this._sliderBackgroundStyle.hover.background = this._whitePixel;
this._sliderBackgroundStyle.active.background = this._whitePixel;
this._sliderBackgroundStyle.focused.background = this._whitePixel;
this._sliderThumbStyle = new GUIStyle();
this._sliderThumbStyle.stretchHeight = true;
this._sliderThumbStyle.fixedWidth = 20f;
this._sliderThumbStyle.normal.background = this._blackPixel;
this._sliderThumbStyle.hover.background = this._blackPixel;
this._sliderThumbStyle.active.background = this._blackPixel;
this._sliderThumbStyle.focused.background = this._blackPixel;
}
void OnGUI()
{
this._sliderValue = GUI.HorizontalSlider(new Rect(100, 100, 200f, 20f), this._sliderValue, 0, 1, this._sliderBackgroundStyle, this._sliderThumbStyle);
}
}

How to use TextButtonStyle.overFont?

I'm trying to use overFont and overColor on TextButton so the button appearance can changes when the mouse move over.
Here's the style I defined.
var buttonStyle = new TextButtonStyle();
buttonStyle.fontColor = new Color(1f, 1f, 1f, 1f);
buttonStyle.disabledFontColor = new Color(0, 0, 0, 0.4f);
buttonStyle.down = skin.getDrawable( "button_down");
buttonStyle.up= skin.getDrawable( "button_up");
buttonStyle.over= skin.getDrawable( "button_over");
buttonStyle.overFontColor = new Color(0, 0.3f, 0.3f, 1f);
buttonStyle.font = font
skin.add("default", buttonStyle);
The button is created as follows:
var startGameButton = new TextButton("Start game", skin);
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
stage.addActor(startGameButton);
/*startGameButton.addListener ([ Event e |
Gdx.app.log ("App", "Start game") ;
return true ;
])*/
startGameButton.addListener (new ChangeListener () {
override changed(ChangeEvent event, Actor actor) {
Gdx.app.log ("App", "Start game") ;
}
})
While the down and up state are properly taken into account, the over properties are not used: the button doesn't change when the mouse enters the button area.
buttonStyle.fontOverColor = Color.BLUE; works fine for me,
try to pass to your TextButton constructor not skin, but buttonStyle,
in TextButton there is such constructor
public TextButton (String text, TextButtonStyle style)
It's difficult to say something else, because code not looks like real working code, I mean var keyword or this code is not correct (there is no public variables x, y, width, height):
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
If changing constructor will not help you, please post your real code.

how to add tooltip to pushpin on windowsphone

I've been doing a essay about map on windows phone. I added pushpins default into map and its content is a image. I want to show information when I tap or click on pushpin, but I don't know what to do. I've just thought about use tooltip to show info, but I can't do it.
here is my createpushpin function.
can you help me? thank you for all kind of you!
private void CreateNewPushpin(object selectedItem)
{
var pushpinPrototype = selectedItem as Pushpinsmodel;
var pushpinicon = pushpinPrototype.Icon;
Pushpin pushpins = new Pushpin() { Tag = adress.Name };
pushpins.Background = new SolidColorBrush(Colors.Green);
pushpins.Location = new GeoCoordinate(lad, long);
ImageBrush image = new ImageBrush() {
ImageSource = new System.Windows.Media.Imaging.BitmapImage
(pushpinicon)};
Ellipse elip = new Ellipse()
{
Fill = image,
Name = adress.Name,
StrokeThickness = 10,
Height = 30,
Width = 30
};
pushpins.Content = elip;
var tooltipText = new ToolTip { Content = adress.Name};
ToolTipService.SetToolTip(pushpins, tooltipText);
map1.Children.Add(pushpins);
listpushpin.Add(pushpins);
this.map1.SetView(pushpins.Location, 18.0);
}

WP7 Popup not showing

In my app I want to display a simple string within a popup when the user clicks on an image. For this I added a Tap gesture listener to the image and within the handler I have the following code:
private void GestureListener_Tap( object sender, GestureEventArgs e )
{
var img = sender as Image;
if( img == null ) {
return;
}
Point pos = e.GetPosition( img );
string text = "I'm a popup!";
var popup = new Popup() {
Child = new Border() {
BorderBrush = new SolidColorBrush( Colors.LightGray ),
Child = new TextBlock() {
Text = text,
TextWrapping = TextWrapping.Wrap,
},
},
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalOffset = pos.X,
VerticalOffset = pos.Y,
Visibility = Visibility.Visible,
};
popup.IsOpen = true;
Debug.WriteLine( "GestureListener_Tap: " + text );
}
The call to WriteLine prints in the debugger output window but the popup doesn't get displayed. What am I doing wrong here?
Thanks for your help!
I tried your code and the Popup is displayed. I think the problem for you is the Position for the Image relative to the Mouse. Try to set another Background for the Parent Container and I think you'll see the Popup. You can also try to play around with
Point pos = e.GetPosition(null);
until you get the Position you require

Resources