A version of the StringElement that can be styled with a number of formatting options and can render images or background images either from UIImage parameters or by downloading them from the net.
Inheritance: StringElement, IImageUpdated, IColorizeBackground
Esempio n. 1
0
		public void DemoStyled () 
		{
			var imageBackground = new Uri ("file://" + Path.GetFullPath ("background.png"));
			var image = ImageLoader.DefaultRequestImage (imageBackground, null);
			var small = image.Scale (new SizeF (32, 32));
			
			var imageIcon = new StyledStringElement ("Local image icon") {
				Image = small
			};
			var backgroundImage = new StyledStringElement ("Image downloaded") {
				BackgroundUri = new Uri ("http://www.google.com/images/logos/ps_logo2.png")
			};
			var localImage = new StyledStringElement ("Local image"){
				BackgroundUri = imageBackground
			};
			
			var backgroundSolid = new StyledStringElement ("Solid background") {
				BackgroundColor = UIColor.Green
			};
			var colored = new StyledStringElement ("Colored", "Detail in Green") {
				TextColor = UIColor.Yellow,
				BackgroundColor = UIColor.Red,
				DetailColor = UIColor.Green,
			};
			var sse = new StyledStringElement ("DetailDisclosureIndicator") { Accessory = UITableViewCellAccessory.DetailDisclosureButton };
			sse.AccessoryTapped += delegate {
				var alert = new UIAlertView ("Accessory", "Accessory clicked!", null, "Ok");
				alert.Show ();
			};
			var root = new RootElement("Styled Elements") {
				new Section ("Image icon"){
					imageIcon
				},
				new Section ("Background") { 
					backgroundImage, backgroundSolid, localImage
				},
				new Section ("Text Color"){
					colored
				},
				new Section ("Cell Styles"){
					new StyledStringElement ("Default", "Invisible value", UITableViewCellStyle.Default),
					new StyledStringElement ("Value1", "Aligned on each side", UITableViewCellStyle.Value1),
					new StyledStringElement ("Value2", "Like the Addressbook", UITableViewCellStyle.Value2),
					new StyledStringElement ("Subtitle", "Makes it sound more important", UITableViewCellStyle.Subtitle),
					new StyledStringElement ("Subtitle", "Brown subtitle", UITableViewCellStyle.Subtitle) {
						 DetailColor = UIColor.Brown
					}
				},
				new Section ("Accessories"){
					new StyledStringElement ("DisclosureIndicator") { Accessory = UITableViewCellAccessory.DisclosureIndicator },
					new StyledStringElement ("Checkmark") { Accessory = UITableViewCellAccessory.Checkmark },
					sse
				}
			};
			
			var dvc = new DialogViewController (root, true);
			navigation.PushViewController (dvc, true);
		}
Esempio n. 2
0
		public void DemoLoadMore () 
		{
			Section loadMore = new Section();
			
			var s = new StyledStringElement ("Hola") {
				BackgroundUri = new Uri ("http://www.google.com/images/logos/ps_logo2.png")
				//BackgroundColor = UIColor.Red
			};
			loadMore.Add (s);
			loadMore.Add (new StringElement("Element 1"));
			loadMore.Add (new StringElement("Element 2"));
			loadMore.Add (new StringElement("Element 3"));
						
			
			loadMore.Add (new LoadMoreElement("Load More Elements...", "Loading Elements...", lme => {
				// Launch a thread to do some work
				ThreadPool.QueueUserWorkItem (delegate {
					
					// We just wait for 2 seconds.
					System.Threading.Thread.Sleep(2000);
				
					// Now make sure we invoke on the main thread the updates
					navigation.BeginInvokeOnMainThread(delegate {
						lme.Animating = false;
						loadMore.Insert(loadMore.Count - 1, new StringElement("Element " + (loadMore.Count + 1)),
				    		            new StringElement("Element " + (loadMore.Count + 2)),
				            		    new StringElement("Element " + (loadMore.Count + 3)));
					
					});
				});
				
			}, UIFont.BoldSystemFontOfSize(14.0f), UIColor.Blue));
							
			var root = new RootElement("Load More") {
				loadMore
			};
			
			var dvc = new DialogViewController (root, true);
			navigation.PushViewController (dvc, true);
		}
Esempio n. 3
0
		//
		// Creates one of the various StringElement classes, based on the
		// properties set.   It tries to load the most memory efficient one
		// StringElement, if not, it fallsback to MultilineStringElement or
		// StyledStringElement
		//
		static Element LoadString (JsonObject json, object data)
		{
			string value = null;
			string caption = value;
			string background = null;
			NSAction ontap = null;
			NSAction onaccessorytap = null;
			int? lines = null;
			UITableViewCellAccessory? accessory = null;
			UILineBreakMode? linebreakmode = null;
			UITextAlignment? alignment = null;
			UIColor textcolor = null, detailcolor = null;
			UIFont font = null;
			UIFont detailfont = null;
			UITableViewCellStyle style = UITableViewCellStyle.Value1;

			foreach (var kv in json){
				string kvalue = (string) kv.Value;
				switch (kv.Key){
				case "caption":
					caption = kvalue;
					break;
				case "value":
					value = kvalue;
					break;
				case "background":	
					background = kvalue;
					break;
				case "style":
					style = ToCellStyle (kvalue);
					break;
				case "ontap": case "onaccessorytap":
					string sontap = kvalue;
					int p = sontap.LastIndexOf ('.');
					if (p == -1)
						break;
					NSAction d = delegate {
						string cname = sontap.Substring (0, p);
						string mname = sontap.Substring (p+1);
						foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()){
							Type type = a.GetType (cname);
						
							if (type != null){
								var mi = type.GetMethod (mname, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
								if (mi != null)
									mi.Invoke (null, new object [] { data });
								break;
							}
						}
					};
					if (kv.Key == "ontap")
						ontap = d;
					else
						onaccessorytap = d;
					break;
				case "lines":
					int res;
					if (int.TryParse (kvalue, out res))
						lines = res;
					break;
				case "accessory":
					accessory = ToAccessory (kvalue);
					break;
				case "textcolor":
					textcolor = ParseColor (kvalue);
					break;
				case "linebreak":
					linebreakmode = ToLinebreakMode (kvalue);
					break;
				case "font":
					font = ToFont (kvalue);
					break;
				case "subtitle":
					value = kvalue;
					style = UITableViewCellStyle.Subtitle;
					break;
				case "detailfont":
					detailfont = ToFont (kvalue);
					break;
				case "alignment":
					alignment = ToAlignment (kvalue);
					break;
				case "detailcolor":
					detailcolor = ParseColor (kvalue);
					break;
				case "type":
					break;
				default:
					Console.WriteLine ("Unknown attribute: '{0}'", kv.Key);
					break;
				}
			}
			if (caption == null)
				caption = "";
			if (font != null || style != UITableViewCellStyle.Value1 || detailfont != null || linebreakmode.HasValue || textcolor != null || accessory.HasValue || onaccessorytap != null || background != null || detailcolor != null){
				StyledStringElement styled;
				
				if (lines.HasValue){
					styled = new StyledMultilineElement (caption, value, style);
					styled.Lines = lines.Value;
				} else {
					styled = new StyledStringElement (caption, value, style);
				}
				if (ontap != null)
					styled.Tapped += ontap;
				if (onaccessorytap != null)
					styled.AccessoryTapped += onaccessorytap;
				if (font != null)
					styled.Font = font;
				if (detailfont != null)
					styled.SubtitleFont = detailfont;
				if (detailcolor != null)
					styled.DetailColor = detailcolor;
				if (textcolor != null)
					styled.TextColor = textcolor;
				if (accessory.HasValue)
					styled.Accessory = accessory.Value;
				if (linebreakmode.HasValue)
					styled.LineBreakMode = linebreakmode.Value;
				if (background != null){
					if (background.Length > 1 && background [0] == '#')
						styled.BackgroundColor = ParseColor (background);
					else
						styled.BackgroundUri = new Uri (background);
				}
				if (alignment.HasValue)
					styled.Alignment = alignment.Value;
				return styled;
			} else {
				StringElement se;
				if (lines == 0)
					se = new MultilineElement (caption, value);
				else
					se = new StringElement (caption, value);
				if (alignment.HasValue)
					se.Alignment = alignment.Value;
				if (ontap != null)
					se.Tapped += ontap;
				return se;
			}
		}