public MasterViewController (IntPtr handle) : base (handle) { InvokeAddNewItem = () => { this.AddNewItem (null, null); }; InvokeTapItem = (index) => { var val = default(UInt32); if (UInt32.TryParse (index, out val)) { TableView.SelectRow (NSIndexPath.Create(0,val), true, UITableViewScrollPosition.Top); this.PerformSegue("showDetail", this); } else throw new Exception (string.Format ("Unable to parse index parameter of '{0}'", index)); }; Title = NSBundle.MainBundle.LocalizedString ("Master", "Master"); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { PreferredContentSize = new CGSize (320f, 600f); ClearsSelectionOnViewWillAppear = false; } // Custom initialization }
public override CGSize SizeThatFits(CGSize size) { var result = new CGSize(size.Width, this.size); if (size.Width == float.MaxValue) result.Width = 0; return result; }
public OverlayScene (CGSize size) : base (size) { AnchorPoint = new CGPoint (0.5f, 0.5f); ScaleMode = SKSceneScaleMode.ResizeFill; float scale = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 1.5f : 1f; var myImage = SKSpriteNode.FromImageNamed (ResourceManager.GetResourcePath ("speedGauge.png")); myImage.AnchorPoint = new CGPoint (0.5f, 0f); myImage.Position = new CGPoint (size.Width * 0.33f, -size.Height * 0.5f); myImage.XScale = 0.8f * scale; myImage.YScale = 0.8f * scale; AddChild (myImage); var needleHandle = SKNode.Create (); var needle = SKSpriteNode.FromImageNamed (ResourceManager.GetResourcePath ("needle.png")); needleHandle.Position = new CGPoint (0f, 16f); needle.AnchorPoint = new CGPoint (0.5f, 0f); needle.XScale = 0.7f; needle.YScale = 0.7f; needle.ZRotation = (float)Math.PI / 2f; needleHandle.AddChild (needle); myImage.AddChild (needleHandle); SpeedNeedle = needleHandle; var cameraImage = SKSpriteNode.FromImageNamed (ResourceManager.GetResourcePath ("video_camera.png")); cameraImage.Position = new CGPoint (-size.Width * 0.4f, -size.Height * 0.4f); cameraImage.Name = "camera"; cameraImage.XScale = 0.6f * scale; cameraImage.YScale = 0.6f * scale; AddChild (cameraImage); }
void ApplyCurrentTheme() { CGSize gradientImageSize = new CGSize(TabBar.Frame.Size.Width, TabBar.Frame.Size.Height); UIImage gradientImage = ImageUtils.GetGradientImage( Theme.Current.MainGradientStartColor.CGColor, Theme.Current.MainGradientEndColor.CGColor, gradientImageSize); TabBar.TintColor = UIColor.FromPatternImage(gradientImage); }
public override void Draw(CGRect rect) { Graphics g = Graphics.FromCurrentContext (); g.Clear (Color.Wheat); var mainBundle = NSBundle.MainBundle; var filePath = mainBundle.PathForResource ("CocoaMono", "png"); var bitmap = Image.FromFile (filePath); filePath = mainBundle.PathForResource ("tiger-Q300", "png"); var tiger = Image.FromFile (filePath); using (var ig = Graphics.FromImage (bitmap)) { var pen = new Pen (Brushes.Yellow, 20); var rec = new CGSize (200, 200); var recp = new CGPoint (bitmap.Width - rec.Width - pen.Width / 2, bitmap.Height - rec.Height - pen.Width / 2); ig.DrawEllipse (pen, (RectangleF)new CGRect(recp, rec)); } g.DrawImage (bitmap, 50f, 50f); g.DrawImage (tiger, 200f, 200f); using (var brush = new SolidBrush (BACKCOLOR)) { Image pic = GetCircleImage (); //get circle image var newSize = new CGSize (pic.Size.Width * SCALE, pic.Size.Height * SCALE); //calculate new size of circle g.FillEllipse (brush, (RectangleF)new CGRect (circleLocation, newSize)); //draw the shape background g.DrawImage (pic, (RectangleF)new CGRect (circleLocation, newSize)); //draw the hatch style } g.Dispose (); }
public WeatherScene(CGSize size) : base(size) { backgroundSprite = SKSpriteNode.FromImageNamed ("b11.png"); backgroundSprite.Position = new CGPoint (Size.Width / 2, Size.Height / 2); backgroundSprite.Size = new CGSize(this.Size.Height / backgroundSprite.Size.Height * backgroundSprite.Size.Width, Size.Height); AddChild(backgroundSprite); }
public override void ViewWillTransitionToSize (CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) { if (toSize.Width > 320.0f) { ForcedTraitCollection = UITraitCollection.FromHorizontalSizeClass (UIUserInterfaceSizeClass.Regular); } else { ForcedTraitCollection = new UITraitCollection (); } base.ViewWillTransitionToSize (toSize, coordinator); }
public TOCroppedImageAttributes (CGRect croppedFrame, global::System.nint angle, CGSize originalSize) : base (NSObjectFlag.Empty) { IsDirectBinding = GetType ().Assembly == global::ApiDefinition.Messaging.this_assembly; if (IsDirectBinding) { InitializeHandle (global::ApiDefinition.Messaging.IntPtr_objc_msgSend_CGRect_nint_CGSize (this.Handle, Selector.GetHandle ("initWithCroppedFrame:angle:originalImageSize:"), croppedFrame, angle, originalSize), "initWithCroppedFrame:angle:originalImageSize:"); } else { InitializeHandle (global::ApiDefinition.Messaging.IntPtr_objc_msgSendSuper_CGRect_nint_CGSize (this.SuperHandle, Selector.GetHandle ("initWithCroppedFrame:angle:originalImageSize:"), croppedFrame, angle, originalSize), "initWithCroppedFrame:angle:originalImageSize:"); } }
public override void ViewDidLoad () { base.ViewDidLoad (); PreferredContentSize = new CGSize (PreferredContentSize.Width, 55f); UpdateTitle (); WidgetButton.SetTitle ("Tap here to register", UIControlState.Normal); WidgetButton.TouchUpInside += (sender, e) => UIApplication.SharedApplication.OpenUrl (new NSUrl ("evolveCountdown://")); }
public static CGRect GetBoundingRect (this NSString This, CGSize size, NSStringDrawingOptions options, UIStringAttributes attributes, NSStringDrawingContext context) { // Define attributes var attr = new NSMutableDictionary (); attr.Add (NSFont.NameAttribute, attributes.Font.NSFont); var rect = This.BoundingRectWithSize (size, options, attr); // HACK: Cheating on the height return new CGRect(rect.Left, rect.Top , rect.Width, rect.Height * 1.5f); }
public MasterViewController(IntPtr handle) : base(handle) { Title = NSBundle.MainBundle.LocalizedString ("Master", "Master"); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { PreferredContentSize = new CGSize (320f, 600f); ClearsSelectionOnViewWillAppear = false; } // Custom initialization }
protected override CGSize CalculatePreferredSize(CGSize availableSpace) { nfloat height = granularSpacing.Values.Sum(); nfloat width = 0; foreach (var subview in Subviews) { var preferredSize = subview.SizeThatFits(new CGSize(availableSpace.Width, float.MaxValue)); height += preferredSize.Height; width = (nfloat)Math.Max(width, preferredSize.Width); } return new CGSize(width, height); }
protected override CGSize CalculatePreferredSize(CGSize availableSpace) { nfloat height = 0; nfloat width = 0; foreach (var subview in Subviews) { var preferredSize = subview.SizeThatFits(new CGSize(availableSpace.Width, nfloat.MaxValue)); width += preferredSize.Width; height = (nfloat)Math.Max(height, preferredSize.Height); } return new CGSize(width, height); }
public static void EndImageContext() { // Return to previous context if (PreviousContext != null) { NSGraphicsContext.CurrentContext = PreviousContext; } // Release memory Context = null; PreviousContext = null; ColorSpace = null; ImageSize = CGSize.Empty; }
public override CGSize SizeThatFits(CGSize size) { NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle (); paragraphStyle.Alignment = this.Style.TextAlignment; NSDictionary attributes = new NSDictionary (UIStringAttributeKey.Font, UIFont.SystemFontOfSize (18), UIStringAttributeKey.ForegroundColor, this.Style.TextColor, UIStringAttributeKey.ParagraphStyle, paragraphStyle); CGSize textSize = (new NSString (this.Text)).WeakGetSizeUsingAttributes (attributes); CGSize labelSize = new SizeF ((float)(textSize.Width - 1.5 * (this.Style.Insets.Left + this.Style.Insets.Right) + Math.Abs (this.Style.ShadowOffset.Width)), (float)(textSize.Height - 1.5 * (this.Style.Insets.Top + this.Style.Insets.Bottom) + Math.Abs (this.Style.ShadowOffset.Height))); return labelSize; }
protected override CGSize CalculatePreferredSize(CGSize availableSpace) { nfloat maxWidth = 0f; nfloat maxHeight = 0f; foreach (var subview in Subviews) { var size = subview.SizeThatFits(availableSpace); maxWidth = (nfloat)Math.Max(maxWidth, size.Width); maxHeight = (nfloat)Math.Max(maxHeight, size.Height); } return new CGSize(maxWidth, maxHeight); }
public static void BeginImageContextWithOptions(CGSize size, bool opaque, nfloat scale) { // Create new image context ColorSpace = CGColorSpace.CreateDeviceRGB (); Context = new CGBitmapContext (null, (int)size.Width, (int)size.Height, 8, 0, ColorSpace, CGImageAlphaInfo.PremultipliedLast); // Flip context vertically var flipVertical = new CGAffineTransform(1,0,0,-1,0,size.Height); Context.ConcatCTM (flipVertical); // Save previous context ImageSize = size; PreviousContext = NSGraphicsContext.CurrentContext; NSGraphicsContext.CurrentContext = NSGraphicsContext.FromCGContext (Context, true); }
public override void Draw(CGRect rect) { Graphics g = Graphics.FromCurrentContext (); // Create a pen object: var aPen = new Pen (Color.Blue, 4); // Set line caps and dash style: aPen.StartCap = LineCap.Flat; aPen.EndCap = LineCap.ArrowAnchor; aPen.DashStyle = DashStyle.Dot; aPen.DashOffset = 50; //draw straight line: g.DrawLine (aPen, 50, 30, 200, 30); // define point array to draw a curve: var point1 = new Point (50, 200); var point2 = new Point (100, 75); var point3 = new Point (150, 60); var point4 = new Point (200, 160); var point5 = new Point (250, 250); Point[] Points = { point1, point2, point3, point4, point5 }; g.DrawCurve (aPen, Points); aPen.Dispose (); //Text rotation: CGRect ClientRectangle = rect; string s = "A simple text string"; var rectangle = new CGRect ((int)ClientRectangle.X, (int)ClientRectangle.Y, (int)ClientRectangle.Width, (int)ClientRectangle.Height); drawingRectangle = new CGRect (rectangle.Location, rectangle.Size); var sz = new CGSize (rectangle.Width, rectangle.Height); var font = new Font ("Arialss", 14f, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline); CGSize stringSize = g.MeasureString (s, font); var Middle = new CGPoint (sz.Width / 30, sz.Height / 2 - (int)stringSize.Height / 2); g.DrawLine (Pens.Black, new Point (0, (int)(rectangle.Height / 2)), new Point ((int)rectangle.Width, (int)(rectangle.Height / 2))); g.DrawLine (Pens.Black, new Point ((int)(rectangle.Width / 2), 0), new Point ((int)(rectangle.Width / 2), (int)rectangle.Height)); g.TranslateTransform ((float)Middle.X, (float)Middle.Y); g.RotateTransform (-90); var format = new StringFormat (); format.Alignment = StringAlignment.Center; g.DrawString (s, font, Brushes.Black, 0, 0, format); g.Dispose (); }
public override nfloat GetHeightForRow (UITableView tableView, NSIndexPath indexPath) { var cell = tableView.DequeueReusableCell (CellIdentifier) as MessageCell; Message item = Messages.FindMessage (TableItems, indexPath.Row); //---- if there are no cells to reuse, create a new one if (cell == null) { cell = new MessageCell ( CellIdentifier); } cell.UpdateCell (item.name, item.message, item.date); CGSize size = new CGSize (tableView.Bounds.Width - 40, float.MaxValue); height = cell.messageLabel.Text.StringSize(cell.messageLabel.Font, size, UILineBreakMode.WordWrap).Height; Console.WriteLine("set height to" + (height + 44)); return height + 44; }
public static UIImage CreateLabelImage(Color color) { var size = new CGSize(28f, 28f); var cgColor = UIColor.FromRGB(color.R, color.G, color.B).CGColor; UIGraphics.BeginImageContextWithOptions(size, false, 0); var ctx = UIGraphics.GetCurrentContext(); ctx.SetLineWidth(1.0f); ctx.SetStrokeColor(cgColor); ctx.AddEllipseInRect(new CGRect(0, 0, size.Width, size.Height)); ctx.SetFillColor(cgColor); ctx.FillPath(); var image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return image; }
public static UIImage ImageFromFont(UIFont font, char character, UIColor fillColor) { var s = new NSString("" + character); var stringSize = s.StringSize(font); var maxSize = (nfloat)Math.Max(stringSize.Height, stringSize.Width); var size = new CGSize(maxSize, maxSize); UIGraphics.BeginImageContextWithOptions(size, false, 0f); fillColor.SetFill(); var drawPoint = new CGPoint((size.Width / 2f) - (stringSize.Width / 2f), (size.Height / 2f) - (stringSize.Height / 2f)); s.DrawString(drawPoint, font); var img = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return img; }
public nfloat GetHeight (UITableView tableView, NSIndexPath indexPath) { try { if (tableView.Style == UITableViewStyle.Grouped) { //float margin = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone ? 20f : 110f; CGSize size = new CGSize (tableView.Bounds.Width /* - margin */, float.MaxValue); return Height(new CGRect(tableView.Bounds.Location, size)); } return Height(tableView.Bounds); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Attempted to get cell height resulted in exception: " + e.Message); } return 0f; }
public static string GetSplashLogo( CGSize screenSize, nfloat scalar ) { nfloat nativeWidth = screenSize.Width * scalar; nfloat nativeHeight = screenSize.Height * scalar; // default to iphone4s, cause..why not. string imageName = "splash_logo_iphone4s.png"; // compare the dimensions with the known iDevice sizes, and return the appropriate string. if ( nativeWidth == 640 && nativeHeight == 960 ) { imageName = "splash_logo_iphone4s.png"; } else if ( nativeWidth == 640 && nativeHeight == 1136 ) { imageName = "splash_logo_iphone5.png"; } else if ( nativeWidth == 750 && nativeHeight == 1334 ) { imageName = "splash_logo_iphone6.png"; } else if ( nativeWidth == 1242 && nativeHeight == 2208 ) { imageName = "splash_logo_iphone6p.png"; } else if ( nativeWidth == 2048 && nativeHeight == 1536 ) { imageName = "splash_logo_ipad_landscape_2x.png"; } else if ( nativeWidth == 1024 && nativeHeight == 768 ) { imageName = "splash_logo_ipad_landscape.png"; } else if ( nativeWidth == 1536 && nativeHeight == 2048 ) { imageName = "splash_logo_ipad_portrait_2x.png"; } else if ( nativeWidth == 768 && nativeHeight == 1024 ) { imageName = "splash_logo_ipad_portrait.png"; } return imageName; }
public override void ViewWillLayoutSubviews () { base.ViewWillLayoutSubviews (); CGRect bounds = View.Bounds; CGSize imageSize = backgroundView.Image.Size; nfloat imageAspectRatio = imageSize.Width / imageSize.Height; nfloat viewAspectRatio = bounds.Width / bounds.Height; if (viewAspectRatio > imageAspectRatio) { // Let the background run off the top and bottom of the screen, so it fills the width var scaledSize = new CGSize (bounds.Width, bounds.Width / imageAspectRatio); var location = new CGPoint (0, (bounds.Height - scaledSize.Height) / 2f); backgroundView.Frame = new CGRect (location, scaledSize); } else { // Let the background run off the left and right of the screen, so it fills the height var scaledSize = new CGSize (imageAspectRatio * bounds.Height, bounds.Height); var location = new CGPoint ((bounds.Width - scaledSize.Width) / 2f, 0); backgroundView.Frame = new CGRect (location, scaledSize); } }
/// <summary> /// Shows the action sheet picker from the view that was set as the owner. /// </summary> public void Show () { // declare vars float titleBarHeight = 40; CGSize doneButtonSize = new CGSize (71, 30); CGSize actionSheetSize = new CGSize (owner.Frame.Width, DatePicker.Frame.Height + titleBarHeight); CGRect datePickerFrame = new CGRect (0, owner.Frame.Height - actionSheetSize.Height , actionSheetSize.Width, actionSheetSize.Height); // show the action sheet and add the controls to it //actionSheet.ShowInView (owner); owner.AddSubview (datePickerView); // Set the Y offset of the frame 100, so that it can be brought back upwards in a slide animation datePickerFrame.Offset (0, 100); // resize the date picker frame to fit our other stuff datePickerView.Frame = datePickerFrame; // move our picker to be at the bottom of the actionsheet (view coords are relative to the action sheet) DatePicker.Frame = new CGRect ((nfloat)DatePicker.Frame.X, titleBarHeight, DatePicker.Frame.Width, DatePicker.Frame.Height); // move our label to the top of the action sheet titleLabel.Frame = new CGRect (10, 4, owner.Frame.Width - 100, 35); // move our button doneButton.Frame = new CGRect (actionSheetSize.Width - doneButtonSize.Width - 10, 7, doneButtonSize.Width, doneButtonSize.Height); // First set the alpha of the datePickerView to 0 to prepare for a fade in animation datePickerView.Alpha = 0; // Store datePickerView.Frame in the temporary variable to allow it to be animated datePickerFrame = datePickerView.Frame; UIView.Animate (0.2, () => { datePickerFrame.Offset (0, -100); datePickerView.Frame = datePickerFrame; datePickerView.Alpha = 1; }); }
public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) { CGSize oldSize = View.Bounds.Size; if (oldSize != toSize) { UIInterfaceOrientation prevOrientation = InterfaceOrientation; // In iOS 8+ DidRotate is no longer called after a rotation // But we need to notify iOSGamePlatform to update back buffer so we explicitly call it // We do this within the animateAlongside action, which at the point of calling // will have the new InterfaceOrientation set coordinator.AnimateAlongsideTransition((context) => { DidRotate(prevOrientation); }, (context) => { }); } base.ViewWillTransitionToSize(toSize, coordinator); }
private CGSize squareSize (CGSize size) { return new CGSize(size.Width > size.Height ? size.Width : size.Height, size.Width > size.Height ? size.Width : size.Height); }
CGSize DescriptionSize () { if (!HasDescription) { return CGSize.Empty; } var boundedSize = new CGSize (AvailableWidth, float.MaxValue); CGSize descriptionLabelSize; if (!IsRunningiOS7OrLater ()) { var attr = new UIStringAttributes (NSDictionary.FromObjectAndKey (TitleFont, (NSString)TitleFont.Name)); descriptionLabelSize = Description.GetBoundingRect ( boundedSize, NSStringDrawingOptions.TruncatesLastVisibleLine, attr, null) .Size; } else { descriptionLabelSize = Description.StringSize ( DescriptionFont, boundedSize, UILineBreakMode.TailTruncation); } return descriptionLabelSize; }
public override CGSize SizeThatFits (CGSize size) { return new CGSize(size.Width, 150); }
protected override CGSize CalculatePreferredSize(CGSize availableSpace) { return new CGSize(fixedWidth ?? 0, fixedHeight ?? 0); }