本文整理汇总了C#中UIButton.SetImage方法的典型用法代码示例。如果您正苦于以下问题:C# UIButton.SetImage方法的具体用法?C# UIButton.SetImage怎么用?C# UIButton.SetImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIButton
的用法示例。
在下文中一共展示了UIButton.SetImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetBitmapItems
public void SetBitmapItems(UIImage[] unselectedImages, UIImage[] selectedImages)
{
_segmentCount = unselectedImages.Length;
// set the new frame size
Frame = new RectangleF(Frame.Left, Frame.Top, BUTTON_WIDTH * unselectedImages.Length, BUTTON_WIDTH);
// kill the old views
foreach (var view in Subviews)
view.RemoveFromSuperview();
// add the new views
for (int ii = 0; ii < unselectedImages.Length; ii++)
{
UIButton view = new UIButton(new RectangleF(BUTTON_WIDTH * ii, 0, BUTTON_WIDTH, BUTTON_WIDTH))
{ BackgroundColor = UIColor.White };
view.SetImage(unselectedImages[ii], UIControlState.Normal);
if (selectedImages != null && selectedImages.Length > ii)
view.SetImage(selectedImages[ii], UIControlState.Selected);
//var index = ii;
view.TouchUpInside += delegate(object sender, EventArgs e) {
handleSelection(sender as UIButton);
};
AddSubview(view);
}
}
示例2: ViewWillAppear
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear (animated);
if (centerButton == null){
centerButton = UIButton.FromType(UIButtonType.Custom);
centerButton.AutoresizingMask = UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin;
centerButton.SetImage(normalState, UIControlState.Normal);
centerButton.SetImage(highlightedState, UIControlState.Highlighted);
centerButton.Frame = new RectangleF(0,0,normalState.Size.Width, normalState.Size.Height);
PointF center = TabBar.Center;
center.Y = (TabBar.Frame.Size.Height / 2.0f);
centerButton.Center = center;
if (Tapped != null){
centerButton.TouchUpInside += delegate(object sender, EventArgs e) {
Tapped();
};
}
this.TabBar.AddSubview(centerButton);
this.TabBar.BringSubviewToFront(centerButton);
Console.WriteLine(centerButton.Center);
//this.View.AddSubview(centerButton);
//this.View.BringSubviewToFront(centerButton);
}
}
示例3: SetButtonImage
private void SetButtonImage(UIButton button, string imageurl, string placeholderurl)
{
if(File.Exists(imageurl))
button.SetImage(new UIImage(imageurl), UIControlState.Normal);
else if(File.Exists(placeholderurl))
button.SetImage(new UIImage(placeholderurl), UIControlState.Normal);
button.Layer.MasksToBounds = true;
button.Layer.CornerRadius = 5.0f;
}
示例4: SetButtonBackground
public static void SetButtonBackground(UIButton button, bool value)
{
if (value)
{
button.SetImage(YesImage, UIControlState.Normal);
}
else
{
button.SetImage(NoImage, UIControlState.Normal);
}
}
示例5: LoadView
public override void LoadView ()
{
base.LoadView ();
window = AppDelegate.TogglWindow;
View.BackgroundColor = UIColor.White;
_panGesture = new UIPanGestureRecognizer (OnPanGesture) {
CancelsTouchesInView = true
};
menuButtons = new[] {
(logButton = new UIButton ()),
(reportsButton = new UIButton ()),
(settingsButton = new UIButton ()),
(feedbackButton = new UIButton ()),
(signOutButton = new UIButton ()),
};
logButton.SetTitle ("LeftPanelMenuLog".Tr (), UIControlState.Normal);
logButton.SetImage (Image.TimerButton, UIControlState.Normal);
logButton.SetImage (Image.TimerButtonPressed, UIControlState.Highlighted);
reportsButton.SetTitle ("LeftPanelMenuReports".Tr (), UIControlState.Normal);
reportsButton.SetImage (Image.ReportsButton, UIControlState.Normal);
reportsButton.SetImage (Image.ReportsButtonPressed, UIControlState.Highlighted);
settingsButton.SetTitle ("LeftPanelMenuSettings".Tr (), UIControlState.Normal);
settingsButton.SetImage (Image.SettingsButton, UIControlState.Normal);
settingsButton.SetImage (Image.SettingsButtonPressed, UIControlState.Highlighted);
feedbackButton.SetTitle ("LeftPanelMenuFeedback".Tr (), UIControlState.Normal);
feedbackButton.SetImage (Image.FeedbackButton, UIControlState.Normal);
feedbackButton.SetImage (Image.FeedbackButtonPressed, UIControlState.Highlighted);
signOutButton.SetTitle ("LeftPanelMenuSignOut".Tr (), UIControlState.Normal);
signOutButton.SetImage (Image.SignoutButton, UIControlState.Normal);
signOutButton.SetImage (Image.SignoutButtonPressed, UIControlState.Highlighted);
logButton.HorizontalAlignment = reportsButton.HorizontalAlignment = settingsButton.HorizontalAlignment =
feedbackButton.HorizontalAlignment = signOutButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
var authManager = ServiceContainer.Resolve<AuthManager> ();
authManager.PropertyChanged += OnUserLoad;
foreach (var button in menuButtons) {
button.Apply (Style.LeftView.Button);
button.TouchUpInside += OnMenuButtonTouchUpInside;
View.AddSubview (button);
}
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
View.AddConstraints (MakeConstraints (View));
View.AddGestureRecognizer (_panGesture);
}
示例6: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Title = "Buttons";
View.BackgroundColor = UIColor.White;
buttonStarRect = UIButton.FromType(UIButtonType.RoundedRect);
buttonStarRect.SetImage (UIImage.FromFile ("star-gold45.png"), UIControlState.Normal);
buttonStarRect.SetImage (UIImage.FromFile ("star-grey45.png"), UIControlState.Disabled);
buttonStarRect.Frame = new CGRect(160, 20, 45, 42);
buttonStarRect.TouchUpInside += HandleTouchUpInside;
buttonStarCustom = UIButton.FromType(UIButtonType.Custom);
buttonStarCustom.SetImage (UIImage.FromFile ("star-gold45.png"), UIControlState.Normal);
buttonStarCustom.SetImage (UIImage.FromFile ("star-gold45_sel.png"), UIControlState.Highlighted);
buttonStarCustom.SetImage (UIImage.FromFile ("star-grey45.png"), UIControlState.Disabled);
buttonStarCustom.Frame = new CGRect(160, 70, 45, 42);
buttonStarCustom.TouchUpInside += HandleTouchUpInside;
switchEnabled = new UISwitch(new CGRect(140, 130, 50, 30));
switchEnabled.ValueChanged += (sender, e) => {
buttonStarRect.Enabled = switchEnabled.On;
buttonStarCustom.Enabled = switchEnabled.On;
};
switchEnabled.On = true;
#region Not related to sample
rectLabel = new UILabel(new CGRect(10, 20, 150, 30));
rectLabel.Text = "RoundedRect:";
customLabel = new UILabel(new CGRect(10, 70, 150, 30));
customLabel.Text = "Custom:";
switchLabel = new UILabel(new CGRect(10, 130, 150, 30));
switchLabel.Text = "Enabled:";
View.AddSubview (rectLabel);
View.AddSubview (customLabel);
View.AddSubview (switchLabel);
#endregion
View.AddSubview (buttonStarRect);
View.AddSubview (buttonStarCustom);
View.AddSubview (switchEnabled);
}
示例7: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
scrollView = new UIScrollView {
BackgroundColor = UIColor.Black,
Frame = new CGRect (0, 0, 320, View.Bounds.Height * 3)
};
hamburgerMenu = new UIButton {
Frame = new CGRect (10, 10, 25, 25)
};
hamburgerMenu.SetImage (UIImage.FromFile ("HamburgerMenu.png"), UIControlState.Normal);
hamburgerMenu.TouchUpInside += (sender, e) => {
flyout.ToggleMenu ();
};
photoGalleryView = new PhotoGalleryView (View.Bounds) {
Frame = new CGRect (0, 0, View.Bounds.Width, View.Bounds.Height)
};
scrollView.Add (photoGalleryView);
scrollView.Add (hamburgerMenu);
View.Add (scrollView);
}
示例8: ViewDidLoad
/// <summary>
/// Calls when view are loaded
/// </summary>
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Create toolbar, title label and button
var toolBar = new UIToolbar(new RectangleF(0, 0, View.Bounds.Width, 44));
toolBar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleBottomMargin;
toolBar.BarStyle = UIBarStyle.Black;
var toolBarTitle = new UILabel(new RectangleF(0, 0, View.Bounds.Width, 44));
toolBarTitle.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
toolBarTitle.BackgroundColor = UIColor.Clear;
toolBarTitle.TextAlignment = UITextAlignment.Center;
toolBarTitle.TextColor = UIColor.White;
toolBarTitle.Font = UIFont.SystemFontOfSize(18.0f);
toolBarTitle.Text = "Note".t();
var btnNavigate = new UIButton(new RectangleF(5, 5, 30, 30));
btnNavigate.SetImage(UIImage.FromFile("Images/Toolbar/Save32.png"), UIControlState.Normal);
btnNavigate.TouchUpInside += delegate {
mNote.Note = mNoteTxt.Text;
DocumentNoteManager.Instance.SaveNote(mNote);
CallbackAction(mNoteTxt);
mPopoverController.Dismiss(true);
};
toolBar.AddSubview(toolBarTitle);
toolBar.AddSubview(btnNavigate);
View.AddSubview(toolBar);
// Create text note
mNoteTxt = new UITextView(new RectangleF(0, 44, View.Bounds.Width, View.Bounds.Height));
mNoteTxt.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
mNoteTxt.Font = UIFont.SystemFontOfSize(17.0f);
mNoteTxt.Text = mNote.Note;
View.AddSubview(mNoteTxt);
}
示例9: GetBackButton
private static UIView GetBackButton(float viewWidth, float viewHeight)
{
UIView view = new UIView(new RectangleF(0, viewHeight - BUTTONHEIGHT, BUTTONWIDTH, BUTTONHEIGHT));
view.BackgroundColor = UIColor.Clear;
UIButton button = new UIButton(new RectangleF(0, 0, BUTTONWIDTH, BUTTONHEIGHT));
button.SetImage(BACKBUTTONIMAGEOUT, UIControlState.Normal);
button.AdjustsImageWhenDisabled = false;
button.AdjustsImageWhenHighlighted = false;
UILabel backTitle = new UILabel(new RectangleF(50, 10, 60, 25));
backTitle.Text = "返回";
backTitle.TextColor = UIColor.FromRGB(255, 255, 255);
backTitle.Font = UIFont.FromName(FONTFAMILY, 18);
backTitle.TextAlignment = UITextAlignment.Center;
backTitle.BackgroundColor = UIColor.Clear;
button.Add(backTitle);
button.TouchUpInside += (sender, e) =>
{
button.SetImage(BACKBUTTONIMAGEOUT, UIControlState.Normal);
CloseTimePiker();
};
button.TouchDown += (sender, e) =>
{
button.SetImage(BACKBUTTONIMAGEIN, UIControlState.Normal);
};
button.TouchDragInside += (sender, e) =>
{
button.SetImage(BACKBUTTONIMAGEOUT, UIControlState.Normal);
};
view.Add(button);
return view;
}
示例10: ViewDidAppear
public override void ViewDidAppear(bool animated)
{
base.ViewWillAppear (animated);
UINavigationController nav = NavigationController;
MainViewController controller = (MainViewController)nav.ParentViewController; // MainViewController : ZUUIRevealController
// Check if a UIPanGestureRecognizer already sits atop our NavigationBar.
if (nav.NavigationBar.GestureRecognizers == null ||
!(nav.NavigationBar.GestureRecognizers.Contains (navigationBarPanGestureRecognizer))) {
// If not, allocate one and add it.
UIPanGestureRecognizer panGestureRecognizer = new UIPanGestureRecognizer (controller.RevealGesture);
navigationBarPanGestureRecognizer = panGestureRecognizer;
NavigationController.NavigationBar.AddGestureRecognizer (navigationBarPanGestureRecognizer);
}
// Check if we have a revealButton already.
if (NavigationItem.LeftBarButtonItem == null) {
// If not, allocate one and add it.
UIImage imageMenu = UIImage.FromFile ("action_menu.png");
UIButton menuButton = new UIButton (UIButtonType.Custom);
menuButton.SetImage (imageMenu, UIControlState.Normal);
menuButton.Frame = new RectangleF (0.0f, 0.0f, (float)imageMenu.Size.Width, (float)imageMenu.Size.Height);
menuButton.TouchUpInside += (sender, e) => controller.RevealToggle ();
NavigationItem.LeftBarButtonItem = new UIBarButtonItem (menuButton);
}
}
示例11: ItemView
public ItemView(Item item)
{
this.item = item;
AddSubview (button = new UIButton {
ContentMode = UIViewContentMode.ScaleAspectFill,
Layer = {
ShadowColor = UIColor.Black.CGColor,
ShadowRadius = .3f,
ShadowOpacity = .3f,
ShadowOffset = new SizeF (1f, 1),
},
});
button.TouchUpInside += (object sender, EventArgs e) => onTap ();
button.SetImage (image = ImageLoader.Load (item.Image).ImageWithRenderingMode (UIImageRenderingMode.AlwaysTemplate), UIControlState.Normal);
label = new UILabel {
AdjustsFontSizeToFitWidth = true,
Font = UIFont.BoldSystemFontOfSize (100),
TextAlignment = UITextAlignment.Center,
Text = "0",
Layer = {
ShadowColor = UIColor.Black.CGColor,
ShadowOpacity = .25f,
ShadowRadius = .3f,
ShadowOffset = new SizeF (1f, 1),
}
};
xScale = (float)random.NextDouble ();
yScale = (float)random.NextDouble ();
var s = Math.Max (random.NextDouble (), .5);
scale = (float)Math.Min (s, .9);
}
示例12: Setup
private void Setup()
{
//Label
autocompleteLabel = new UILabel(CGRect.Empty);
autocompleteLabel.Font = this.Font;
autocompleteLabel.BackgroundColor = UIColor.Clear;
autocompleteLabel.TextColor = UIColor.LightGray;
autocompleteLabel.LineBreakMode = UILineBreakMode.Clip;
autocompleteLabel.Hidden = true;
this.AddSubview(autocompleteLabel);
this.BringSubviewToFront(autocompleteLabel);
//Button
autocompleteButton = new UIButton(UIButtonType.Custom);
autocompleteButton.AddTarget(OnButtonCliced, UIControlEvent.TouchUpInside);
autocompleteButton.SetImage(UIImage.FromBundle("autocompleteButton"), UIControlState.Normal);
this.AddSubview(autocompleteButton);
this.BringSubviewToFront(autocompleteButton);
autocompleteString = string.Empty;
NSNotificationCenter.DefaultCenter.AddObserver((NSString)UITextFieldTextDidChangeNotification, OnUITextFieldTextDidChangeNotification);
}
示例13: BarcodeScan
private void BarcodeScan()
{
scanner = new MobileBarcodeScanner(this.NavigationController);
//buttonDefaultScan = new UIButton(UIButtonType.RoundedRect);
//buttonDefaultScan.Frame = new RectangleF(40, 150, 280, 40);
// buttonDefaultScan = new UIButton(UIButtonType.Custom) {
// Frame = new CGRect(View.Center.X - (View.Bounds.Width - 40) / 2, View.Center.Y - 50, View.Bounds.Width - 40, 100),
// BackgroundColor = UIColor.FromRGB(0, 0.5f, 0),
// };
UIButton buttonDefaultScan = new UIButton (
new CoreGraphics.CGRect (20, View.Center.Y - 100, View.Bounds.Width - 40, 250));
UIImage roundImage = new UIImage ("RoundButton60.png");
buttonDefaultScan.SetImage (roundImage, UIControlState.Normal);
buttonDefaultScan.BackgroundColor = UIColor.Clear;
// BizappTheme.Apply (buttonDefaultScan);
//buttonDefaultScan.Frame = new RectangleF(40, View.Bounds.Height/2.0f, 280, 40);
// buttonDefaultScan.SetTitle("Scan Barcode", UIControlState.Normal);
buttonDefaultScan.TouchUpInside += async (sender, e) =>
{
//Tell our scanner to use the default overlay
scanner.UseCustomOverlay = false;
//We can customize the top and bottom text of the default overlay
scanner.TopText = "Hold camera up to barcode to scan";
scanner.BottomText = "Barcode will automatically scan";
//Start scanning
var result = await scanner.Scan ();
HandleScanResult(result);
};
this.View.AddSubview (buttonDefaultScan);
}
示例14: DateTimeElement2
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;
}
示例15: SetImageFor
public static void SetImageFor(string imagePath, UIButton button, UIControlState state)
{
using (UIImage img = UIImage.FromFile(imagePath)) {
Assert.NotNull(img);
button.SetImage(img, state);
}
}