I am having an issue where my UISearchBar does not resize on phone rotation unless I touch on the search bar so that it has focus (see images below).
The search bar is created and added to a UIMapView as a subview. See code.
Searchbar creation:
public UISearchController DefineSearchController()
{
_searchResultsController = new SearchResultsVC(_mapView);
_searchResultsController.searchItemSelected += PlaceSelect;
_searchUpdater = new SearchResultsUpdator();
_searchUpdater.UpdateSearchResults += _searchResultsController.Search;
//add the search controller
var searchController = new UISearchController(_searchResultsController)
{
SearchResultsUpdater = _searchUpdater
};
var scb = searchController.SearchBar;
scb.SizeToFit();
scb.SearchBarStyle = UISearchBarStyle.Minimal;
var img = UIImage.FromBundle("tabSpace");
scb.SetBackgroundImage(img, UIBarPosition.Top, UIBarMetrics.Default);
var textField = scb.ValueForKey(new NSString("searchField")) as UITextField;
if (textField != null)
{
var backgroundView = textField.Subviews[0];
if (backgroundView != null)
{
backgroundView.BackgroundColor = UIColor.White;
backgroundView.Layer.BorderColor = AppColour.PersianBlue.GetUIColour().CGColor;
backgroundView.Layer.BorderWidth = 1;
backgroundView.Layer.CornerRadius = 10;
backgroundView.ClipsToBounds = true;
}
}
var localEnterPoI = NSBundle.MainBundle.LocalizedString("placeHolderSearchForLocation", "Enter a PoI to search for");
scb.Placeholder = localEnterPoI;
searchController.Delegate = new SearchControllerDelegate();
searchController.HidesNavigationBarDuringPresentation = false;
return searchController;
}
Added to the subview:
//Define Search Controller
_mapSearchManager = new MapSearchManager(_mapView);
_searchController = _mapSearchManager.DefineSearchController();
var scb = _searchController.SearchBar;
_mapView.AddSubview(scb);
NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[]{
scb.TopAnchor.ConstraintEqualTo(_mapView.TopAnchor, 30),
scb.LeadingAnchor.ConstraintEqualTo(_mapView.LeadingAnchor, 10),
scb.TrailingAnchor.ConstraintEqualTo(_mapView.LeadingAnchor, -10),
});
I heave search extensively and was only able to find one similar issue:
UISearchBar doesn't resize when frame is resized in IOS 11
I implementing both of suggestion but it didn't make any difference.
Has anyone else encounted this or know what a possible solution might be.
Cheers
Related
I am trying to remove the light shade of Navigationbar in ios. Below is the code I tried. Also tried different scenarios, still the shade is not removed. I am using XF 4.5.0.356. Is there anything to do to get the exact color of my Navigationbar?
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
var appearance = new UINavigationBarAppearance();
appearance.ConfigureWithTransparentBackground();
appearance.LargeTitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.White };
appearance.BackgroundColor = UIColor.Orange;
UINavigationBar.Appearance.CompactAppearance = appearance;
UINavigationBar.Appearance.StandardAppearance = appearance;
UINavigationBar.Appearance.ScrollEdgeAppearance = appearance;
UINavigationBar.Appearance.Translucent = false;
}
You should set the appearance to current NavigationController.NavigationBar:
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
var appearance = new UINavigationBarAppearance();
appearance.ConfigureWithTransparentBackground();
appearance.LargeTitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.White };
appearance.BackgroundColor = UIColor.Orange;
this.NavigationController.NavigationBar.CompactAppearance = appearance;
this.NavigationController.NavigationBar.StandardAppearance = appearance;
this.NavigationController.NavigationBar.ScrollEdgeAppearance = appearance;
this.NavigationController.NavigationBar.Translucent = false;
}
I want to add a new pin on clicking on the map using Xamarin.Forms.Maps.
After searching , I found that I have to use TKCustomMap plugin .. but it didn't show on the map .. just empty area
and this is my code
double lit = 2.394;// double.Parse(Center.CenterLocationX);
double longt = 43.2352;// double.Parse(Center.CenterLocationY);
TK.CustomMap.Position position = new TK.CustomMap.Position(lit, longt);
TK.CustomMap.MapSpan span = TK.CustomMap.MapSpan.FromCenterAndRadius(position, TK.CustomMap.Distance.FromMiles(0.5));
TK.CustomMap.TKCustomMap map = new TK.CustomMap.TKCustomMap(span);
map.IsShowingUser = true;
map.MapType = TK.CustomMap.MapType.Street;
TK.CustomMap.TKCustomMapPin pin = new TK.CustomMap.TKCustomMapPin()
{
//Address = "Test",
//Label = "Test",
Position = position,
IsDraggable = true
//Type = PinType.SearchResult
};
map.MapClicked += (x, y) =>
{
SharedTools.MakeToast("Clicked");
};
//map.Pins.Add(pin);
map.Pins = new List<TK.CustomMap.TKCustomMapPin>() { pin };
map.MoveToMapRegion(span);
layout.Content = map;
I want to solve this, or any other idea to add pin on click
I used your code in my demo, i got the result like the following screenshot(If you cannot see the band of google, you should check the API_KEY, if it is correct.)
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="API_KEY" />
Then i changed the lit to 37, longt to -122 and add pin on click.I can see the map and get the following result. Please check your lit and longt, if the value is legal
There is my code.
public partial class MainPage : ContentPage
{
TK.CustomMap.TKCustomMap map;
TK.CustomMap.Position position;
public MainPage()
{
InitializeComponent();
//37,-122
double lit = 37;// double.Parse(Center.CenterLocationX);
double longt = -122;// double.Parse(Center.CenterLocationY);
position = new TK.CustomMap.Position(lit, longt);
TK.CustomMap.MapSpan span = TK.CustomMap.MapSpan.FromCenterAndRadius(position, TK.CustomMap.Distance.FromMiles(0.5));
map = new TK.CustomMap.TKCustomMap(span);
map.IsShowingUser = true;
map.MapType = TK.CustomMap.MapType.Street;
map.MapClicked += OnMapClicked;
Content = map;
}
private void OnMapClicked(object sender, TKGenericEventArgs<Position> e)
{
TK.CustomMap.TKCustomMapPin pin = new TK.CustomMap.TKCustomMapPin()
{
//Address = "Test",
//Label = "Test",
Position = position
,
IsDraggable = true
//Type = PinType.SearchResult
};
map.Pins = new List<TK.CustomMap.TKCustomMapPin>() { pin };
}
}
Here is my demo.Hope this can help you.
https://github.com/851265601/TKGoogleMapsDemo
As the title says, I am using TeeChart to draw several boxplots within one chart object. Since, the number of boxplots can be quite big, I want to be able to click on a box and have information pertaining to that series to show up as a tooltip.
I am currently trying to do this with a MarksTip but for some reason, when I try to hover over the box, MarksTip will sometimes open and then immediately close (basically being visible for a split second). I have already tried setting the hide delay but it seems to be ignoring that.
Code snippet below:
seriesIndex = 0;
foreach (var seriesData in seriesDataList)
{
var series = new Box()
series.UseCustomValues = true;
series.Box.HorizSize = 5;
series.Box.Style = PointerStyles.Rectangle;
series.MildOut.Visible = true;
series.MildOut.HorizSize = 2;
series.MildOut.VertSize = 2;
series.ExtrOut.Visible = true;
series.ExtrOut.HorizSize = 2;
series.ExtrOut.VertSize = 2;
series.LinePen.Visible = _isLineVisible;
series.Pointer.Pen.Visible = true;
series.ShowInLegend = false;
series.Add(seriesIndex, seriesData);
series.Title = "tooltip text";
var tooltip = new MarksTip(Chart.Chart)
{
Series = series,
Style = MarksStyles.SeriesTitle,
HideDelay = 31000,
};
Chart.Series.Add(series);
seriesIndex++;
}
Credit to this other question for pointing me in the right direction.
I ended up using the GetSeriesMark event to modify the text of a single chart-bound MarksTip instead of creating multiple series-bound `MarksTip
seriesIndex = 0;
Chart.Tools.Add(new MarksTip());
foreach (var seriesData in seriesDataList)
{
var series = new Box()
series.UseCustomValues = true;
//Other series appearance stuff
series.Add(seriesIndex, seriesData);
series.Title = "tooltip text";
series.GetSeriesMark += (s, args) =>
{
args.MarkText = s.Title;
};
series.Marks.Visible = false;
Chart.Series.Add(series);
seriesIndex++;
}
One note about this method. The tooltip will only appear when hovering over actual datapoints and not the whole box. Not ideal but at least I can read the tooltip now.
So in our Report we have an ImageBox in the Detail Band which we want to have a different image per page.
Seeing that changing it in the BeforePrint Event of the Detail Band doesn't work (since it's only called once per print of the Report) I followed the following approach so far (which doesn't work):
In the PrintOnPage Event of a label of the Page Header Band of the Report (in order to have it called per page and be able to use the PrintOnPageEventArgs in the new XRPictureBox - I need the PageIndex):
private void xrLabel10_PrintOnPage(object sender, PrintOnPageEventArgs e)
{
this.Detail.Controls.Remove(xrPictureBox1); //Existing PictureBox control
this.Detail.Controls.Add(PictureBox(e));
}
Which calls this:
private List<Bitmap> _imageList;
public XRPictureBox PictureBox(PrintOnPageEventArgs e)
{
XRPictureBox pictureBox = new XRPictureBox();
var articleService = DependencyResolver.Current.GetService<IArticleService>();
int width;
int height;
pictureBox.Name = "xrPictureBox_" + e.PageIndex;
pictureBox.BackColor = Color.Transparent;
pictureBox.Dpi = 254F;
pictureBox.LocationFloat = new DevExpress.Utils.PointFloat(108.4792F, 71.4375F);
pictureBox.Name = "xrPictureBox_" + e.PageIndex;
pictureBox.SizeF = new SizeF(950F, 1225F);
pictureBox.Sizing = ImageSizeMode.Squeeze;
pictureBox.StylePriority.UseBackColor = false;
if (ReportUnit == ReportUnit.HundredthsOfAnInch)
{
width = (int)(GraphicsUnitConverter.Convert(xrPictureBox1.Size.Width, GraphicsUnit.Inch, GraphicsUnit.Pixel) / 100);
height = (int)(GraphicsUnitConverter.Convert(xrPictureBox1.Size.Height, GraphicsUnit.Inch, GraphicsUnit.Pixel) / 100);
}
else
{
width = (int)(GraphicsUnitConverter.Convert(xrPictureBox1.Size.Width, GraphicsUnit.Millimeter, GraphicsUnit.Pixel) / 10);
height = (int)(GraphicsUnitConverter.Convert(xrPictureBox1.Size.Height, GraphicsUnit.Millimeter, GraphicsUnit.Pixel) / 10);
}
if (_imageList == null)
{
_imageList = articleService .GetListOfImages((int)articleId.Value, width, height, PageColor); //this gets a List<Bitmap>
}
if (_imageList[e.PageIndex] == null)
return null;
pictureBox.Image = _imageList[e.PageIndex];
return pictureBox;
}
So basically my idea was to replace the existing Control with a new XRPictureBox with the new image. But it just doesn't appear in the Report, even though while debugging I see the code being run and retrieving the correct images for the correct pages.
Edit: nempoBu4's answer is correct generally, but unfortunately I failed to clarify an additional issue which makes it not perfect for my situation:
The report also has a subreport right next to the PictureBox and this subreport can expand to more than one pages. We wanted the PictureBox to render a different image in each of these pages and they don't trigger the PrintOnPage event of the PictureBox. I will add an answer with the workaround we found as soon as I can :)
PictureBox
You can use the PrintOnPage event of your PictureBox itself.
Here is example:
var source = new List<Tuple<int, string>>();
for (int index = 0; index < 100; index++)
source.Add(new Tuple<int, string>(index, "Name" + index));
var pictureBox = new XRPictureBox();
pictureBox.PrintOnPage += (sender, e) =>
{
if (_imageList[e.PageIndex] == null)
return;
pictureBox.Image = _imageList[e.PageIndex];
};
var labelItem1 = new XRLabel();
labelItem1.DataBindings.Add("Text", null, "Item1");
labelItem1.LeftF = 100;
var labelItem2 = new XRLabel();
labelItem2.DataBindings.Add("Text", null, "Item2");
labelItem2.LeftF = 200;
var detail = new DetailBand();
detail.Controls.AddRange(new XRControl[] { pictureBox, labelItem1, labelItem2 });
var report = new XtraReport();
report.Bands.Add(detail);
report.DataSource = source;
report.ShowRibbonPreview();
The result of example:
Watermarks
If you want to have only one image per page then you can use watermarks.
Here is example:
var source = new List<Tuple<int, string>>();
for (int index = 0; index < 100; index++)
source.Add(new Tuple<int, string>(index, "Name" + index));
var labelItem1 = new XRLabel();
labelItem1.DataBindings.Add("Text", null, "Item1");
labelItem1.LeftF = 100;
var labelItem2 = new XRLabel();
labelItem2.DataBindings.Add("Text", null, "Item2");
labelItem2.LeftF = 200;
var detail = new DetailBand();
detail.Controls.AddRange(new XRControl[] { labelItem1, labelItem2 });
var report = new XtraReport();
report.Bands.Add(detail);
report.DataSource = source;
report.CreateDocument();
foreach (Page page in report.Pages)
if (_imageList[page.Index] != null)
{
var watermark = new Watermark();
watermark.Image = _imageList[page.Index];
page.AssignWatermark(watermark);
}
report.ShowRibbonPreview();
Here is result:
I've got the following UIActionSheet.
How do I add it to my top navigation bar?
Preferably as the far right button.
var sheet = new UIActionSheet ("");
sheet.AddButton ("Discard Picture");
sheet.AddButton ("Pick New Picture");
sheet.AddButton ("Cancel");
sheet.CancelButtonIndex = 2;
// Dummy buttons to preserve the space for the UIImageView
for (int i = 0; i < 4; i++) {
sheet.AddButton("");
sheet.Subviews[i+4].Alpha = 0; // And of course it's better to hide them
}
var subView = new UIImageView();
subView.ContentMode = UIViewContentMode.ScaleAspectFill;
subView.Frame = new RectangleF(23,185,275,210);
// Late Steve Jobs loved rounded corners. Let's have some respect for him
subView.Layer.CornerRadius = 10;
subView.Layer.MasksToBounds = true;
subView.Layer.BorderColor = UIColor.Black.CGColor;
sheet.AddSubview(subView);
NavigationController.Add(sheet);
You can show an ActionSheet using the ShowFrom methods.
In particular, ShowFromToolbar shows the sheet from the top toolbar button.
Here's an example which shows the sheet in different ways depending on whether you are on tablet or phone:
void ActionMenu()
{
//_actionSheet = new UIActionSheet("");
UIActionSheet actionSheet = new UIActionSheet (
"Customer Actions",
null,
"Cancel",
"Delete Customer",
new string[] {"Change Customer"});
actionSheet.Style = UIActionSheetStyle.Default;
actionSheet.Clicked += delegate(object sender, UIButtonEventArgs args) {
switch (args.ButtonIndex)
{
case 0: DeleteCustomer(); break;
case 1: ChangeCustomer(); break;
}
};
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
actionSheet.ShowFromToolbar(NavigationController.Toolbar);
else
actionSheet.ShowFrom(NavigationItem.RightBarButtonItem, true);
}
https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CustomerManagement/CustomerManagement/CustomerManagement.Touch/Views/CustomerView.cs#L67