/// <summary>
		/// Adds the text.
		/// </summary>
		/// <param name="image">The image.</param>
		/// <param name="text">The text.</param>
		/// <param name="point">The point.</param>
		/// <param name="font">The font.</param>
		/// <param name="color">The color.</param>
		/// <param name="alignment">The alignment.</param>
		/// <returns>UIImage.</returns>
		public static UIImage AddText(
			this UIImage image,
			string text,
			CGPoint point,
			UIFont font,
			UIColor color,
			UITextAlignment alignment = UITextAlignment.Left)
		{
			//var labelRect = new RectangleF(point, new SizeF(image.Size.Width - point.X, image.Size.Height - point.Y));
			var h = text.StringHeight(font, image.Size.Width);
			var labelRect = new CGRect(point, new CGSize(image.Size.Width - point.X, h));

			var label = new UILabel(labelRect)
				            {
					            Font = font,
					            Text = text,
					            TextColor = color,
					            TextAlignment = alignment,
					            BackgroundColor = UIColor.Clear
				            };

			var labelImage = label.ToNativeImage();

			using (var context = image.Size.ToBitmapContext())
			{
				var rect = new CGRect(new CGPoint(0, 0), image.Size);
				context.DrawImage(rect, image.CGImage);
				context.DrawImage(labelRect, labelImage.CGImage);
				context.StrokePath();
				return UIImage.FromImage(context.ToImage());
			}
		}
        public StylizedStringAttributes(
            UIFont font,
            UIColor color,
            float letterSpace,
            nfloat lineHeightMultiplier,
            StylizedStringCase stringCase,
            UITextAlignment textAlignment   = UITextAlignment.Left,
            NSUnderlineStyle underlineStyle = NSUnderlineStyle.None)
        {
            _stringCase = stringCase;

            NSMutableParagraphStyle paragraphStyle = null;

            if (lineHeightMultiplier != 1 || textAlignment != UITextAlignment.Left)
            {
                paragraphStyle = new NSMutableParagraphStyle
                {
                    LineHeightMultiple = lineHeightMultiplier,
                    Alignment          = textAlignment
                };
            }

            StringAttributes = new UIStringAttributes
            {
                Font              = font,
                ForegroundColor   = color,
                KerningAdjustment = letterSpace,
                ParagraphStyle    = paragraphStyle,
                UnderlineStyle    = underlineStyle
            };
        }
            public UIView CreateView(
                float x, float y,
                float width, float height,
                int maxTextCount,
                UIColor backGroundColor,
                UITextAlignment align)
            {
                if (m_View != null)
                {
                    return(m_View);
                }

                m_View = new UITextView(new CGRect(x, y, width, height))
                {
                    BackgroundColor = backGroundColor,
                    TextAlignment   = align,

                    UserInteractionEnabled = false,

                    // 編集不可にする
                    Editable = false
                };
                m_MaxTextCount = maxTextCount;

                return(m_View);
            }
        public DateTimeElement2(string caption, DateTime date, DialogViewController dvc) : base(caption, null, null)
        {
            this.Dvc  = dvc;
            DateValue = date;

            // create picker elements
            datePicker               = CreatePicker();
            datePicker.Mode          = UIDatePickerMode.DateAndTime;
            datePicker.ValueChanged += delegate {
                DateValue = datePicker.Date;
                Value     = FormatDate(DateValue);
                RefreshValue();

                if (DateSelected != null)
                {
                    DateSelected(this);
                }
            };

            //datePicker.Frame = PickerFrameWithSize (datePicker.SizeThatFits (SizeF.Empty));
            closeBtn = new UIButton(new RectangleF(0, 0, 31, 32));
            closeBtn.SetImage(UIImage.FromFile("Images/closebox.png"), UIControlState.Normal);
            closeBtn.TouchDown += delegate {
                HidePicker();
            };
            datePicker.AddSubview(closeBtn);

            Value = FormatDate(date);

            this.Alignment = UITextAlignment.Left;
        }
        /// <summary>
        /// Adds the text.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="text">The text.</param>
        /// <param name="point">The point.</param>
        /// <param name="font">The font.</param>
        /// <param name="color">The color.</param>
        /// <param name="alignment">The alignment.</param>
        /// <returns>UIImage.</returns>
        public static UIImage AddText(
            this UIImage image,
            string text,
            PointF point,
            UIFont font,
            UIColor color,
            UITextAlignment alignment = UITextAlignment.Left)
        {
            //var labelRect = new RectangleF(point, new SizeF(image.Size.Width - point.X, image.Size.Height - point.Y));
            var h         = text.StringHeight(font, image.Size.Width);
            var labelRect = new RectangleF(point, new SizeF(image.Size.Width - point.X, h));

            var label = new UILabel(labelRect)
            {
                Font            = font,
                Text            = text,
                TextColor       = color,
                TextAlignment   = alignment,
                BackgroundColor = UIColor.Clear
            };

            var labelImage = label.ToNativeImage();

            using (var context = image.Size.ToBitmapContext())
            {
                var rect = new RectangleF(new PointF(0, 0), image.Size);
                context.DrawImage(rect, image.CGImage);
                context.DrawImage(labelRect, labelImage.CGImage);
                context.StrokePath();
                return(UIImage.FromImage(context.ToImage()));
            }
        }
Пример #6
0
 /// <summary>
 /// Create an attributed UILabel.
 /// </summary>
 public static UILabel CreateAttrLabel(string text, UIColor textColor, UIFont font, int lines = 0,
                                       UITextAlignment textAlignment = UITextAlignment.Left, UIColor backgroundColor = null, UIColor strokeColor = null,
                                       float lineSpacing             = 0, float kerning = 0, NSUnderlineStyle underlineStyle     = NSUnderlineStyle.None,
                                       NSShadow shadow = null, float strokeWidth        = 0, NSUnderlineStyle strikeThroughStyle = NSUnderlineStyle.None)
 {
     return(new UILabel {
         Lines = lines,
         TextAlignment = textAlignment,
         AttributedText = new NSAttributedString(
             text,
             font,
             textColor,
             backgroundColor,
             strokeColor,
             paragraphStyle: new NSParagraphStyle {
             LineHeightMultiple = 0,
             LineSpacing = lineSpacing
         },
             NSLigatureType.None,
             kerning,
             underlineStyle,
             shadow,
             strokeWidth,
             strikeThroughStyle)
     });
 }
Пример #7
0
        public void Update(string title, UIColor color, UITextAlignment alignment, bool selectable = false)
        {
            TextLabel.Text          = title;
            TextLabel.TextColor     = color;
            TextLabel.TextAlignment = alignment;

            SelectionStyle = selectable ? UITableViewCellSelectionStyle.Default : UITableViewCellSelectionStyle.None;
        }
        public UIBuddyViewBase <T> TextAlign(UITextAlignment alignment)
        {
            if (Control is UILabel)
            {
                (Control as UILabel).TextAlignment = alignment;
            }

            return(this);
        }
 public static UIView CreateView(
     float x, float y,
     float width, float height,
     int maxTextCount,
     UIColor backGroundColor,
     UITextAlignment align)
 {
     return(null);
 }
Пример #10
0
        public void SetComboboxAlignment(UITextAlignment al)
        {
            if (m_picker == null || m_picker.Model == null)
            {
                return;
            }
            TypePickerViewModel model = m_picker.Model as TypePickerViewModel;

            model.Alignment = al;
        }
Пример #11
0
		public TCEnquiryViewController (string title, string placeholder, string titleButtonOk, string titleButtonCancel, UITextAlignment type, bool ableScroll)
			: base (UserInterfaceIdiomIsPhone ? "TCEnquiryViewController_iPhone" : "TCEnquiryViewController_iPhone", null)
		{
			this.title = title;
			this.placeholder = placeholder;
			this.titleOK = titleButtonOk;
			this.titleCancel = titleButtonCancel;
			this.ableScroll = ableScroll;
			this.type = type;
		}
Пример #12
0
        public static UITextField CreateLabel(string text, UIFont font = null, UITextAlignment alignment = UITextAlignment.Left)
        {
            var label = new UITextField()
            {
                Text = text ?? "",
                Font = font ?? GetSystemFont(false),
            };

            return(label);
        }
 public UILabel CreateLabel(string title = "", UITextAlignment textAlignment = UITextAlignment.Left, bool multiLine = false)
 {
     return(new UILabel
     {
         Text = title,
         TextColor = UIColor.Black,
         TextAlignment = textAlignment,
         Lines = multiLine ? 0 : 1
     });
 }
Пример #14
0
        public static UILabel makeLabel(RectangleF frame, UIColor color, UITextAlignment alignment, Font font, int textSize)
        {
            var label = new UILabel(frame)
            {
                TextColor     = color,
                TextAlignment = alignment,
            };

            label.Font = UIFont.FromName(FontName [font], textSize);
            return(label);
        }
Пример #15
0
 /// <summary>
 /// Create a UILabel.
 /// </summary>
 public static UILabel CreateLabel(string text, UIColor textColor, UIFont font, int lines = 0,
                                   UITextAlignment textAlignment = UITextAlignment.Left)
 {
     return(new UILabel {
         Text = text,
         TextColor = textColor,
         TextAlignment = textAlignment,
         Font = font,
         Lines = lines
     });
 }
 public static UIView CreateView(
     float x, float y,
     float width, float height,
     int maxTextCount,
     UIColor backGroundColor,
     UITextAlignment align)
 {
     return(m_Impl.CreateView(
                x, y,
                width, height,
                maxTextCount,
                backGroundColor,
                align));
 }
Пример #17
0
 public static TextAlignment ConvertToTextAlignment(UITextAlignment alignment)
 {
     switch (alignment)
     {
         case UITextAlignment.Left:
             return TextAlignment.Left;
         case UITextAlignment.Center:
             return TextAlignment.Center;
         case UITextAlignment.Right:
             return TextAlignment.Right;
         default:
             return TextAlignment.Center;
     }
 }
Пример #18
0
        public CustomFontSection(string caption, int fontSize = 24, UITextAlignment alignment = UITextAlignment.Center, UIColor textColor = null) : base("")
        {
            var label = new UILabel();
            var frame = label.Frame;

            frame.Inflate(0, fontSize);
            label.Frame           = frame;
            label.Font            = UIFont.BoldSystemFontOfSize(fontSize);
            label.Text            = caption;
            label.TextAlignment   = alignment;
            label.BackgroundColor = ApplicationColors.DEFAULT_BACKGROUND;
            label.TextColor       = (textColor == null ? ApplicationColors.TABLE_HEADER_FONT : textColor);
            this.HeaderView       = label;
        }
 public CustomFontSection(string caption, int fontSize = 24, UITextAlignment alignment = UITextAlignment.Center, UIColor textColor = null)
     : base("")
 {
     var label = new UILabel ();
     var frame = label.Frame;
     frame.Inflate (0, fontSize);
     label.Frame = frame;
     label.Font = UIFont.BoldSystemFontOfSize (fontSize);
     label.Text = caption;
     label.TextAlignment = alignment;
     label.BackgroundColor = ApplicationColors.DEFAULT_BACKGROUND;
     label.TextColor = (textColor == null ? ApplicationColors.TABLE_HEADER_FONT : textColor);
     this.HeaderView = label;
 }
Пример #20
0
        public static void SetLineSpacing(this UILabel label, float lineSpacing, UITextAlignment alignment)
        {
            var text           = label.Text ?? "";
            var attributedText = new NSMutableAttributedString(text);
            var range          = new NSRange(0, text.Length);

            var paragraphStyle = new NSMutableParagraphStyle();

            paragraphStyle.LineSpacing = lineSpacing;
            paragraphStyle.Alignment   = alignment;

            attributedText.AddAttribute(UIStringAttributeKey.ParagraphStyle, paragraphStyle, range);

            label.AttributedText = attributedText;
        }
Пример #21
0
        private UIStringAttributes CreateAttributesByFont(ref NSMutableAttributedString text, IBaseFont font, FontIndexPair pair = null, FontTag tag = null)
        {
            UIStringAttributes stringAttributes = new UIStringAttributes {
            };

            //add the font
            stringAttributes.Font = TouchAssetPlugin.GetCachedFont(font);

            //add the color
            if (font.Color != System.Drawing.Color.Empty)
            {
                stringAttributes.ForegroundColor = font.Color.ToNativeColor();
            }

            if (pair != null && tag != null)
            {
                if (tag.FontAction == FontTagAction.Link)
                {
                    CreateLink(ref text, ref stringAttributes, font, pair);
                }
            }

            if (font is Font)
            {
                var extendedFont = font as Font;

                if (stringAttributes.ParagraphStyle == null)
                {
                    stringAttributes.ParagraphStyle = new NSMutableParagraphStyle();
                }

                if (extendedFont.Alignment != TextAlignment.None)
                {
                    UITextAlignment alignment = extendedFont.ToNativeAlignment();
                    stringAttributes.ParagraphStyle.Alignment = alignment;
                }

                //add the lineheight
                stringAttributes.ParagraphStyle.LineSpacing = GetPlatformLineHeight(font.Size, extendedFont.LineHeight);

                stringAttributes.ParagraphStyle.LineBreakMode = extendedFont.ToNativeLineBreakMode();

                stringAttributes.ParagraphStyle.LineHeightMultiple = extendedFont.LineHeightMultiplier.HasValue ? (float)extendedFont.LineHeightMultiplier.Value : 0f;
            }

            return(stringAttributes);
        }
Пример #22
0
        public static HorizontalAlign ToEto(this UITextAlignment align)
        {
            switch (align)
            {
            case UITextAlignment.Natural:
            case UITextAlignment.Left:
                return(HorizontalAlign.Left);

            case UITextAlignment.Center:
                return(HorizontalAlign.Center);

            case UITextAlignment.Right:
                return(HorizontalAlign.Right);

            default:
                throw new NotSupportedException();
            }
        }
Пример #23
0
        public static nint ToNative(UITextAlignment value)
        {
            // The values we have in managed code corresponds with the ARM64 values.
            if (!Runtime.IsARM64CallingConvention)
            {
                // Center and Right are switched on x64 on Mac Catalyst
                switch (value)
                {
                case (UITextAlignment)1:
                    value = (UITextAlignment)2;
                    break;

                case (UITextAlignment)2:
                    value = (UITextAlignment)1;
                    break;
                }
            }
            return((nint)(long)value);
        }
Пример #24
0
        public Texture2D(string text, SizeF dim, UITextAlignment alignment, string fontName, float fontSize)
        {
            UIFont font = UIFont.FromName(fontName, fontSize);

            int width = (int)dim.Width;
            if (width != 1 && (width & (width - 1)) != 0) {
                int i = 1;
                while (i < width) {
                    i *= 2;
                }

                width = i;
            }

            int height = (int)dim.Height;
            if (height != 1 && (height & (height - 1)) != 0) {
                int i = 1;
                while (i < height) {
                    i *= 2;
                }
                height = i;
            }

            CGColorSpace colorSpace = CGColorSpace.CreateDeviceGray();

            byte[] data = new byte[width * height];

            unsafe {
                fixed (byte* dataPb = data) {
                    using (CGContext context = new CGBitmapContext((IntPtr)dataPb, width, height, 8, width, colorSpace, CGImageAlphaInfo.None)) {
                        context.SetFillColor(1f, 1f);
                        context.TranslateCTM(0f, height);
                        context.ScaleCTM(1f, -1f);
                        UIGraphics.PushContext(context);
                        text.DrawInRect(new RectangleF(0, 0, dim.Width, dim.Height), font, UILineBreakMode.WordWrap, alignment);
                        UIGraphics.PopContext();
                    }
                }
            }
            colorSpace.Dispose();

            InitWithData(data, Texture2DPixelFormat.A8, width, height, dim);
        }
Пример #25
0
        public void ConfigureForChat(string text, UITextAlignment textAlignment = UITextAlignment.Left, bool hasArrow = false)
        {
            _imageView.Image?.Dispose();
            _imageView.Image = UIImage.FromBundle("arrow_right");

            if (hasArrow)
            {
                _imageView.Hidden             = false;
                _arrowWithConstraint.Constant = 24f;
            }
            else
            {
                _imageView.Hidden             = true;
                _arrowWithConstraint.Constant = 0f;
            }

            UILabelExtensions.SetupLabelAppearance(_label, text, textAlignment == UITextAlignment.Left ? Colors.Black : Colors.GrayIndicator, 15f);
            _label.TextAlignment = textAlignment;
        }
Пример #26
0
        public ToastView(string text, int durationMilliseconds, ToastGravity gravity, int padding, UITextAlignment textAlignment)
        {
            Text = text;
            DurationMilliseconds = durationMilliseconds;
            TextAlignment = textAlignment;
            Padding = padding;
            Gravity = gravity;

            button = UIButton.FromType (UIButtonType.Custom);
            view = button;
            window = UIApplication.SharedApplication.Windows[0];

            OffsetLeft = 0;
            OffsetTop = 0;
            Font = UIFont.SystemFontOfSize (16);
            TextColor = UIColor.White;
            BackgroundColor = UIColor.FromRGBA (0, 0, 0, 0.7f);
            ShadowColor = UIColor.DarkGray;
            ShadowOffset = 1;
        }
Пример #27
0
        private void SetSpannedText(string span, bool force = true)
        {
            if (_view != null && span != null)
            {
                UITextAlignment alignment = _view.TextAlignment;
                UIEdgeInsets    textInset = _view.TextContainerInset;

                var str   = new NSString(string.Format(span, _text));
                var error = new NSError();

                if (_view != null && (force || _blinkAllowed))
                {
                    _view.AttributedText = new NSAttributedString(str.DataUsingEncoding(NSStringEncoding.Unicode)
                                                                  , new NSAttributedStringDocumentAttributes {
                        DocumentType = NSDocumentType.HTML
                    }
                                                                  , ref error);

                    _view.TextAlignment      = alignment;
                    _view.TextContainerInset = textInset;
                }
            }
        }
Пример #28
0
        GetAlignment(string alignment)
        {
            UIControlContentHorizontalAlignment al1 = UIControlContentHorizontalAlignment.Center;
            UITextAlignment al2 = UITextAlignment.Center;

            switch (alignment)
            {
            case "left":
                al1 = UIControlContentHorizontalAlignment.Left;
                al2 = UITextAlignment.Left;
                break;

            case "right":
                al1 = UIControlContentHorizontalAlignment.Right;
                al2 = UITextAlignment.Right;
                break;

            case "top":
            case "bottom":     // there is no top & bottom for iOS, only for Android
            case "center":
                al1 = UIControlContentHorizontalAlignment.Center;
                al2 = UITextAlignment.Center;
                break;

            case "fill":
            case "natural":
                al1 = UIControlContentHorizontalAlignment.Fill;
                al2 = UITextAlignment.Natural;
                break;

            case "justified":
                al1 = UIControlContentHorizontalAlignment.Center;
                al2 = UITextAlignment.Justified;
                break;
            }
            return(new Tuple <UIControlContentHorizontalAlignment, UITextAlignment>(al1, al2));
        }
Пример #29
0
        public async Task HorizontalTextAlignmentInitializesCorrectly()
        {
            var xplatHorizontalTextAlignment = TextAlignment.End;

            var labelStub = new LabelStub()
            {
                Text = "Test",
                HorizontalTextAlignment = xplatHorizontalTextAlignment
            };

            UITextAlignment expectedValue = UITextAlignment.Right;

            var values = await GetValueAsync(labelStub, (handler) =>
            {
                return(new
                {
                    ViewValue = labelStub.HorizontalTextAlignment,
                    NativeViewValue = GetNativeHorizontalTextAlignment(handler)
                });
            });

            Assert.Equal(xplatHorizontalTextAlignment, values.ViewValue);
            values.NativeViewValue.AssertHasFlag(expectedValue);
        }
Пример #30
0
        public static TextAlignment ToTextAlignment(
            this UITextAlignment uiTextAlignment)
        {
            TextAlignment value;

            if (uiTextAlignment == UITextAlignment.Left)
            {
                value = TextAlignment.Start;
            }
            else if (uiTextAlignment == UITextAlignment.Right)
            {
                value = TextAlignment.End;
            }
            else if (uiTextAlignment == UITextAlignment.Center)
            {
                value = TextAlignment.Center;
            }
            else
            {
                throw new NotSupportedException();
            }

            return(value);
        }
Пример #31
0
		public static CGSize DrawString (this NSString item, CGRect rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment) {

			// Get paragraph style
			var labelStyle = new NSMutableParagraphStyle(NSParagraphStyle.DefaultParagraphStyle.MutableCopy() as AppKit.NSMutableParagraphStyle);

			// Adjust alignment
			labelStyle.Alignment = alignment;

			// Adjust line break mode
			labelStyle.LineBreakMode = mode;

			// Define attributes
			var attributes = new NSStringAttributes () {
				Font = font.NSFont,
				ForegroundColor = UIStringDrawing.FillColor,
				ParagraphStyle = labelStyle
			};

			// Preform drawing
			item.DrawInRect(rect, attributes);

			// Return new bounding size
			return new CGSize (rect.Width, rect.Height);
		}
Пример #32
0
 public static UITextField ChangeTextFieldStyle(this UITextField textField, UIFont font, nfloat minimumSize, UIColor textColor, bool translateResize, UITextAlignment aligment)
 {
     textField.TextAlignment   = aligment;
     textField.Font            = font;
     textField.MinimumFontSize = minimumSize;
     textField.TextColor       = textColor;
     textField.TranslatesAutoresizingMaskIntoConstraints = translateResize;
     return(textField);
 }
Пример #33
0
 public static UITextView ChangeTextViewStyle(this UITextView textView, UIFont font, nfloat minimumSize, UIColor textColor, bool translateResize, UITextAlignment aligment)
 {
     textView.TextAlignment = aligment;
     textView.Font          = font;
     textView.TextColor     = textColor;
     textView.TranslatesAutoresizingMaskIntoConstraints = translateResize;
     return(textView);
 }
Пример #34
0
 public static SizeF DrawTextInRect(CGContext context, RectangleF rect, string text, string fontName, float fontSize, CGColor fontColor, UILineBreakMode breakMode, UITextAlignment alignment)
 {
     context.SaveState();
     context.SetFillColor(fontColor);
     NSString str = new NSString(text);
     SizeF size = str.DrawString(rect, UIFont.FromName(fontName, fontSize), breakMode, alignment);
     context.RestoreState();
     return size;
 }
Пример #35
0
 public static void Show(string text, int durationMilliseconds, ToastGravity gravity, int padding, UITextAlignment textAlignment)
 {
     new ToastView (text, durationMilliseconds, gravity, padding, textAlignment).Show();
 }
Пример #36
0
 public CCLabelTTF(string label, SizeF dimensions, UITextAlignment alignment, string fontName, float fontSize)
     : this(label, fontName, fontSize, dimensions, alignment)
 {
 }
Пример #37
0
 /// <summary>
 /// Constructs  an EntryElement for password entry with the given caption, placeholder and initial value.
 /// </summary>
 /// <param name="caption">
 /// The caption to use
 /// </param>
 /// <param name="placeholder">
 /// Placeholder to display.
 /// </param>
 /// <param name="value">
 /// Initial value.
 /// </param>
 /// <param name="isPassword">
 /// True if this should be used to enter a password.
 /// </param>
 public EntryElement(string caption, string placeholder, UITextAlignment alignment, string value, bool isPassword)
     : base(caption)
 {
     Value = value;
     this.isPassword = isPassword;
     this.placeholder = placeholder;
     this.alignment = alignment;
 }
Пример #38
0
 public static UILabel CreateLabel(string text, UIFont font, int fontSize, int labelSize, UITextAlignment alignment, UIColor textColor, UIColor backgroundColor)
 {
     var label = new UILabel (new Rectangle(0,20,300,100));
     label.Lines = 0;
     label.LineBreakMode = UILineBreakMode.WordWrap;
     label.Font = font;
     label.Text = text;
     label.TextAlignment = alignment;
     label.TextColor = textColor;
     label.BackgroundColor = backgroundColor;
     return label;
 }
Пример #39
0
 public AlignmentAttribute(UITextAlignment alignment)
 {
     Alignment = alignment;
 }
Пример #40
0
 /// <summary>
 /// Constructs an EntryElement with the given caption, placeholder and initial value.
 /// </summary>
 /// <param name="caption">
 /// The caption to use
 /// </param>
 /// <param name="placeholder">
 /// Placeholder to display.
 /// </param>
 /// <param name="value">
 /// Initial value.
 /// </param>
 public EntryElement(string caption, string placeholder, UITextAlignment alignment, string value)
     : base(caption)
 {
     Value = value;
     this.placeholder = placeholder;
     this.alignment = alignment;
 }
Пример #41
0
		public TCFeedbackViewController (UITextAlignment type)
			: base (UserInterfaceIdiomIsPhone ? "TCFeedbackViewController_iPhone" : "TCFeedbackViewController_iPhone", null)
		{
			this.type = type;
		}
Пример #42
0
        public static UILabel CreateLabel(string text, bool bold, int fontSize, int labelSize, UITextAlignment alignment, UIColor textColor)
        {
            UIFont font;
            if (bold)
            {
                font = UIFont.BoldSystemFontOfSize(fontSize);
            }
            else
            {
                font = UIFont.SystemFontOfSize(fontSize);
            }

            return CreateLabel(text, font, fontSize, labelSize, alignment, textColor, UIColor.Clear);
        }
		public DateTimeElement2 (string caption, DateTime date, DialogViewController dvc) : base (caption, null, null)
		{			
			this.Dvc = dvc;
			DateValue = date;
			
			// create picker elements
			datePicker = CreatePicker ();
			datePicker.Mode = UIDatePickerMode.DateAndTime; 
			datePicker.ValueChanged += delegate {
				DateValue = datePicker.Date;				
				Value = FormatDate(DateValue);
				RefreshValue();
				
				if (DateSelected != null)
					DateSelected (this);								
			};		
			
			//datePicker.Frame = PickerFrameWithSize (datePicker.SizeThatFits (SizeF.Empty));					
			closeBtn = new UIButton(new RectangleF(0,0,31,32));
			closeBtn.SetImage(UIImage.FromFile("Images/closebox.png"),UIControlState.Normal);
			closeBtn.TouchDown += delegate {
				HidePicker();
			};			
			datePicker.AddSubview(closeBtn);			
						
			Value = FormatDate (date);			
			
			this.Alignment = UITextAlignment.Left;
		}	
Пример #44
0
		void drawLabel (CGContext ctx, CGRect rect, nfloat yCoord, nfloat xCoord, UITextAlignment alignment, string label, bool flipContext = true, bool centerVertical = false)
		{
			// Draw light the sunrise and Sunset labels at the ends of the light box
			using (UIColor fontColor = UIColor.White, shadowColor = UIColor.Black.ColorWithAlpha (0.1f)) {

				var fontAttributes = new UIFontAttributes (new UIFontFeature (CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));

				using (var desc = UIFont.SystemFontOfSize (fontSize).FontDescriptor.CreateWithAttributes (fontAttributes)) {

					using (UIFont font = UIFont.FromDescriptor (desc, fontSize)) {

						// calculating the range of our attributed string
						var range = new NSRange (0, label.Length);

						// set justification for text block
						using (var alignStyle = new NSMutableParagraphStyle { Alignment = alignment }) {

							// add stylistic attributes to out attributed string
							var stringAttributes = new UIStringAttributes {
								ForegroundColor = fontColor,
								Font = font,
								ParagraphStyle = alignStyle
							};

							var target = new CGSize (float.MaxValue, float.MaxValue);

							NSRange fit;

							using (NSMutableAttributedString attrString = new NSMutableAttributedString (label, stringAttributes)) {

								//creating a container for out attributed string 
								using (CTFramesetter framesetter = new CTFramesetter (attrString)) {


									CGSize frameSize = framesetter.SuggestFrameSize (range, null, target, out fit);


									if (alignment == UITextAlignment.Center) xCoord -= (frameSize.Width / 2);

									if (alignment == UITextAlignment.Right) xCoord -= frameSize.Width;


									// subtract the frameSize so the flipped context behaves as expected
									yCoord -= frameSize.Height;

									if (centerVertical) yCoord += (frameSize.Height / 2);


									var textRect = new CGRect (xCoord, yCoord, frameSize.Width, frameSize.Height);

									using (CGPath path = new CGPath ()) {

										path.AddRect (textRect);

										ctx.SetShadow (new CGSize (0.0f, 1.0f), 0.0f, shadowColor.CGColor);

										using (CTFrame frame = framesetter.GetFrame (range, path, null)) {

											if (flipContext) {

												ctx.SaveState ();
												ctx.TranslateCTM (0, rect.Height);
												ctx.ScaleCTM (1, -1);

												frame.Draw (ctx);

												ctx.RestoreState ();

											} else {

												frame.Draw (ctx);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
Пример #45
0
 public static UILabel ChangeLabelStyle(this UILabel label, UIFont font, nfloat minimumSize, UIColor textColor, bool translateResize, UITextAlignment aligment)
 {
     label.TextAlignment   = aligment;
     label.Font            = font;
     label.MinimumFontSize = minimumSize;
     label.TextColor       = textColor;
     label.TranslatesAutoresizingMaskIntoConstraints = translateResize;
     return(label);
 }
Пример #46
0
		public AlignmentAttribute (UITextAlignment alignment) {
			Alignment = alignment;
		}
Пример #47
0
        private Element CreateDataItemElement(DataItem item)
        {
            Element element;

            if ((item.Data.StartsWith(server.CurrentPath)) ||
                (item.Data.StartsWith(ASSETS_LIBRARY)) ||
                (item.Data.StartsWith(BaseDir)))
            {
                var dataElement = new DataImageStringElement(
                    Path.GetFileName(String.IsNullOrEmpty(item.ItemPath) ? item.Data : item.ItemPath),
                    (item.Direction == DataItemDirection.In) ? imgDownload : imgUpload,
                    item.Data
                    );
                dataElement.Tapped += delegate {
                    if (!dataElement.Downloading)
                    {
                        OpenFile(dataElement.Data, item);
                    }
                };
                dataElement.Alignment = (item.Direction == DataItemDirection.In) ? UITextAlignment.Right : UITextAlignment.Left;
                if (item.Data.StartsWith(server.CurrentPath))
                {
                    dataElement.Animating   = true;
                    dataElement.Downloading = true;
                    var localFilePath = Path.Combine(
                        BaseDir,
                        dataElement.Caption);
                    Server.DownloadFileAsync(dataElement.Data,
                                             (s, e) => {
                        var bytes = e.Result;
                        if (bytes == null)
                        {
                            throw e.Error;
                        }
                        var mediaHelper = new MediaHelper();
                        mediaHelper.FileSavedToPhotosAlbum += (sender, args) => {
                            dataElement.Data        = args.ReferenceUrl;
                            item.ItemPath           = args.FilePath;
                            item.Data               = dataElement.Data;
                            dataElement.Animating   = false;
                            dataElement.Downloading = false;
                        };
                        mediaHelper.SaveFileToPhotosAlbum(localFilePath, bytes);
                    }
                                             );
                }
                else
                {
                    dataElement.Animating = false;
                }

                element = (Element)dataElement;
            }
            else
            {
                UITextAlignment alignment   = (item.Direction == DataItemDirection.In) ? UITextAlignment.Right : UITextAlignment.Left;
                var             htmlElement = UIHelper.CreateHtmlViewElement(
                    null,
                    item.Data,
                    alignment
                    );
                element = (Element)htmlElement;
            }

            return(element);
        }
Пример #48
0
 public CCTexture2D(string text, SizeF dimensions, UITextAlignment alignment, CCVerticalTextAlignment vertAlignment, string fontName, float fontSize)
     : this(text, fontName, fontSize, dimensions, alignment, vertAlignment)
 {
 }
Пример #49
0
        void drawLabel(CGContext ctx, CGRect rect, nfloat yCoord, nfloat xCoord, UITextAlignment alignment, string label, bool flipContext = true, bool centerVertical = false)
        {
            // Draw light the sunrise and Sunset labels at the ends of the light box
            using (UIColor fontColor = UIColor.White, shadowColor = UIColor.Black.ColorWithAlpha(0.1f)) {
                var fontAttributes = new UIFontAttributes(new UIFontFeature(CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));

                using (var desc = UIFont.SystemFontOfSize(fontSize).FontDescriptor.CreateWithAttributes(fontAttributes)) {
                    using (UIFont font = UIFont.FromDescriptor(desc, fontSize)) {
                        // calculating the range of our attributed string
                        var range = new NSRange(0, label.Length);

                        // set justification for text block
                        using (var alignStyle = new NSMutableParagraphStyle {
                            Alignment = alignment
                        }) {
                            // add stylistic attributes to out attributed string
                            var stringAttributes = new UIStringAttributes {
                                ForegroundColor = fontColor,
                                Font            = font,
                                ParagraphStyle  = alignStyle
                            };

                            var target = new CGSize(float.MaxValue, float.MaxValue);

                            NSRange fit;

                            using (NSMutableAttributedString attrString = new NSMutableAttributedString(label, stringAttributes)) {
                                //creating a container for out attributed string
                                using (CTFramesetter framesetter = new CTFramesetter(attrString)) {
                                    CGSize frameSize = framesetter.SuggestFrameSize(range, null, target, out fit);


                                    if (alignment == UITextAlignment.Center)
                                    {
                                        xCoord -= (frameSize.Width / 2);
                                    }

                                    if (alignment == UITextAlignment.Right)
                                    {
                                        xCoord -= frameSize.Width;
                                    }


                                    // subtract the frameSize so the flipped context behaves as expected
                                    yCoord -= frameSize.Height;

                                    if (centerVertical)
                                    {
                                        yCoord += (frameSize.Height / 2);
                                    }


                                    var textRect = new CGRect(xCoord, yCoord, frameSize.Width, frameSize.Height);

                                    using (CGPath path = new CGPath()) {
                                        path.AddRect(textRect);

                                        ctx.SetShadow(new CGSize(0.0f, 1.0f), 0.0f, shadowColor.CGColor);

                                        using (CTFrame frame = framesetter.GetFrame(range, path, null)) {
                                            if (flipContext)
                                            {
                                                ctx.SaveState();
                                                ctx.TranslateCTM(0, rect.Height);
                                                ctx.ScaleCTM(1, -1);

                                                frame.Draw(ctx);

                                                ctx.RestoreState();
                                            }
                                            else
                                            {
                                                frame.Draw(ctx);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #50
0
 public CCLabelTTF(string label, SizeF dimensions, UITextAlignment alignment, UILineBreakMode lineBreakMode, string fontName, float fontSize)
     : this(label, fontName, fontSize, dimensions, alignment, lineBreakMode)
 {
 }
Пример #51
0
        public static UIViewElement CreateHtmlViewElement(string caption, string value, UITextAlignment alignment)
        {
            var html = Regex.Replace(value, @"((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)", "<a href='$1'>$1</a>", RegexOptions.Compiled);
            var style = @"<style type='text/css'>body { color: #000; background-color:#e0e0e0; font-family: Helvetica, Arial, sans-serif; font-size:16px; float:" + ((alignment == UITextAlignment.Left) ? "left" : "right") + "; }</style>";
            html = "<html><head>" + style + "</head><body>" + html + "</body>";
            Console.Out.WriteLine("Parsed html: {0}", html);

            var web = new AdvancedWebView();
            web.LoadHtmlString(html, null);

            var size = web.StringSize(html,
                                      UIFont.SystemFontOfSize(10),
                                      new SizeF(UIScreen.MainScreen.Bounds.Width - 20, 2000),
                                      UILineBreakMode.WordWrap);
            float width = size.Width;
            float height = size.Height;
            web.Bounds = new RectangleF(0, 0, width, height);
            web.Center = new PointF(width/2, height/2);

            return new AdvancedUIViewElement(caption, web, false);
        }
Пример #52
0
 public static CGSize DrawString(this string This, CGRect rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment)
 {
     using (var self = ((NSString) This))
         return self.DrawString (rect, font, mode, alignment);
 }