本文整理汇总了C#中UIButton.AddTarget方法的典型用法代码示例。如果您正苦于以下问题:C# UIButton.AddTarget方法的具体用法?C# UIButton.AddTarget怎么用?C# UIButton.AddTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIButton
的用法示例。
在下文中一共展示了UIButton.AddTarget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
var button = new UIButton (UIButtonType.System);
button.Frame = new CGRect(20, this.View.Center.Y - 22, this.View.Frame.Width-40, 44);
button.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleBottomMargin;
button.SetTitle ("Load 10000 items", UIControlState.Normal);
button.AddTarget ((object sender, EventArgs e) => {
int systemVersion = int.Parse(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]);
if (systemVersion < 9) {
var alert = new TKAlert();
alert.Title = "Telerik UI";
alert.Message = "TKListView is optimized for performance when using dynamic item sizing only when running on iOS 9 and upper!";
alert.AddAction(new TKAlertAction("OK", (TKAlert arg1, TKAlertAction arg2) => {
this.CreateListView();
return true;
}));
alert.Show(true);
}
else {
this.CreateListView();
}
((UIView)sender).RemoveFromSuperview();
}, UIControlEvent.TouchUpInside);
this.View.AddSubview(button);
}
示例2: 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);
}
示例3: AddSiteUrl
public void AddSiteUrl(RectangleF frame)
{
url = UIButton.FromType(UIButtonType.Custom);
url.LineBreakMode = UILineBreakMode.TailTruncation;
url.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
url.TitleShadowOffset = new SizeF(0, 1);
url.SetTitleColor(UIColor.FromRGB (0x32, 0x4f, 0x85), UIControlState.Normal);
url.SetTitleColor(UIColor.Red, UIControlState.Highlighted);
url.SetTitleShadowColor(UIColor.White, UIControlState.Normal);
url.AddTarget(delegate { if (UrlTapped != null) UrlTapped (); }, UIControlEvent.TouchUpInside);
// Autosize the bio URL to fit available space
var size = _urlSize;
var urlFont = UIFont.BoldSystemFontOfSize(size);
var urlSize = new NSString(_bio.Url).StringSize(urlFont);
var available = Util.IsPad() ? 400 : 185; // Util.IsRetina() ? 185 : 250;
while(urlSize.Width > available)
{
urlFont = UIFont.BoldSystemFontOfSize(size--);
urlSize = new NSString(_bio.Url).StringSize(urlFont);
}
url.Font = urlFont;
url.Frame = new RectangleF ((float)_left, (float)70, (float)(frame.Width - _left), (float)size);
url.SetTitle(_bio.Url, UIControlState.Normal);
url.SetTitle(_bio.Url, UIControlState.Highlighted);
AddSubview(url);
}
示例4: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
this.View.BackgroundColor = UIColor.White;
this.reservationForm = new ReservationForm ();
this.dataSource = new TKDataFormEntityDataSourceHelper (this.reservationForm);
this.dataFormDelegate = new CustomizationDataFormDelegate ();
NSDateFormatter formatter = new NSDateFormatter ();
formatter.DateFormat = "h:mm a";
this.dataSource.PropertyWithName ("Time").Formatter = formatter;
this.dataSource["Name"].Image = new UIImage ("guest-name.png");
this.dataSource["Phone"].Image = new UIImage ("phone.png");
this.dataSource["Date"].Image = new UIImage ("calendar.png");
this.dataSource["Time"].Image = new UIImage ("time.png");
this.dataSource["Guests"].Image = new UIImage ("guest-number.png");
this.dataSource["Table"].Image = new UIImage ("table-number.png");
this.dataSource["Name"].HintText = "Name";
this.dataSource["Name"].ErrorMessage = @"Please fill in the guest name";
this.dataSource["Time"].EditorClass = new ObjCRuntime.Class(typeof(TKDataFormTimePickerEditor));
this.dataSource["Phone"].EditorClass = new ObjCRuntime.Class(typeof(CallEditor));
this.dataSource ["Phone"].HintText = "Phone";
this.dataSource["Origin"].EditorClass = new ObjCRuntime.Class(typeof(TKDataFormSegmentedEditor));
this.dataSource["Guests"].ValuesProvider = new TKRange (new NSNumber(1), new NSNumber(10));
this.dataSource["Section"].ValuesProvider = NSArray.FromStrings (new string[] {
"Section 1",
"Section 2",
"Section 3",
"Section 4"
});
this.dataSource["Table"].ValuesProvider = NSArray.FromStrings(new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" });
this.dataSource["Origin"].ValuesProvider = NSArray.FromStrings (new string[] {
"phone",
"in-person",
"online",
"other"
});
this.dataSource.AddGroup ("RESERVATION DETAILS", new string[] { "Name", "Phone", "Date", "Time", "Guests" });
this.dataSource.AddGroup ("TABLE DETAILS", new string[] { "Section", "Table" });
this.dataSource.AddGroup ("ORIGIN", new string[] { "Origin" });
this.DataForm.BackgroundColor = UIColor.FromPatternImage (new UIImage ("wood-pattern.png"));
this.DataForm.Frame = new CGRect (0, 0, this.View.Bounds.Size.Width, this.View.Bounds.Size.Height - 66);
this.DataForm.TintColor = new UIColor (0.780f, 0.2f, 0.223f, 1.0f);
this.DataForm.Delegate = this.dataFormDelegate;
this.DataForm.WeakDataSource = this.dataSource.NativeObject;
btn = new UIButton (new CGRect (0, this.DataForm.Frame.Size.Height, this.View.Bounds.Size.Width, 66));
btn.SetTitle ("Cancel Reservation", UIControlState.Normal);
btn.SetTitleColor (new UIColor (0.780f, 0.2f, 0.223f, 1.0f), UIControlState.Normal);
btn.AddTarget (this, new ObjCRuntime.Selector ("CancelReservation"), UIControlEvent.TouchUpInside);
this.View.AddSubview (btn);
}
示例5: LoadButtons
public void LoadButtons()
{
pauseButton = new UIButton(UIButtonType.RoundedRect); pauseButton.Frame = new CGRect(78,291,180,40); pauseButton.SetTitle("Pause",UIControlState.Normal);
resumeButton = new UIButton(UIButtonType.RoundedRect); resumeButton.Frame = new CGRect(78,346,180,40); resumeButton.SetTitle("Resume",UIControlState.Normal);
pauseButton.AddTarget(ClickedPause,UIControlEvent.TouchUpInside);
resumeButton.AddTarget(ClickedResume,UIControlEvent.TouchUpInside);
View.AddSubview(pauseButton);
View.AddSubview(resumeButton);
}
示例6: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
UIButton button = new UIButton (UIButtonType.System);
button.SetTitle ("Tap to load iOS 7 style calendar", UIControlState.Normal);
button.AddTarget (this, new Selector ("ButtonTouched"), UIControlEvent.TouchUpInside);
button.Frame = new CGRect (0, this.View.Bounds.Size.Height / 2f - 20f, this.View.Bounds.Size.Width, 40f);
button.AutoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin |
UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
this.View.AddSubview (button);
}
示例7: CreateButton
public void CreateButton(string title, NSObject target, Selector selector, CGPoint origin)
{
NSString titleString = new NSString (title);
UIStringAttributes attributes = new UIStringAttributes () { Font = UIFont.SystemFontOfSize (18) };
CGSize titleSize = titleString.GetSizeUsingAttributes(attributes);
UIButton button = new UIButton (new CGRect (origin.X, origin.Y, titleSize.Width, 44));
button.TitleLabel.Font = UIFont.SystemFontOfSize (14);
button.Layer.BorderWidth = 1.0f;
button.Layer.BorderColor = UIColor.White.CGColor;
button.Layer.CornerRadius = 3.0f;
button.SetTitle (title, UIControlState.Normal);
button.SetTitleColor (UIColor.White, UIControlState.Normal);
button.AddTarget (target, selector, UIControlEvent.TouchUpInside);
this.SideDrawerView.MainView.AddSubview (button);
}
示例8: Button
public static UIButton Button(UIView View, String Title, Object Target, EventHandler handler)
{
UIButton btn = new UIButton (UIButtonType.Custom);
btn.BackgroundColor = new UIColor (0.5f, 0.7f, 0.2f, 1f);
btn.SetTitleColor (new UIColor (1f, 1f, 1f, 1f), UIControlState.Normal);
btn.SetTitle (Title, UIControlState.Normal);
btn.TitleLabel.Font = UIFont.SystemFontOfSize (12);
btn.Layer.CornerRadius = 40;
btn.ClipsToBounds = true;
btn.Frame = new CGRect ((View.Frame.Size.Width - 80)/2, View.Frame.Size.Height - 180, 80, 80);
btn.AutoresizingMask = UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin;
btn.AddTarget(handler, UIControlEvent.TouchUpInside);
View.AddSubview (btn);
return btn;
}
示例9: CreateButton
public void CreateButton(string title, NSObject target, Selector selector)
{
NSString titleString = new NSString (title);
UIStringAttributes attributes = new UIStringAttributes () { Font = UIFont.SystemFontOfSize (18) };
CGSize titleSize = titleString.GetSizeUsingAttributes(attributes);
UIButton button = new UIButton (new CGRect (15, 15 + buttonY, titleSize.Width, 44));
button.TitleLabel.Font = UIFont.SystemFontOfSize (14);
button.Layer.BorderWidth = 1.0f;
button.Layer.BorderColor = UIColor.White.CGColor;
button.Layer.CornerRadius = 3.0f;
button.SetTitle (title, UIControlState.Normal);
button.SetTitleColor (UIColor.White, UIControlState.Normal);
button.AddTarget (target, selector, UIControlEvent.TouchUpInside);
scrollView.AddSubview (button);
buttonY += 50;
scrollView.ContentSize = new CGSize (Math.Max (button.Frame.Width, scrollView.ContentSize.Width), buttonY + 15 + this.View.Bounds.Y);
}
示例10: NotificationBar
public NotificationBar (NSCoder coder)
: base (coder)
{
heightConstraint = NSLayoutConstraint.Create (this, Height, Equal, null, NoAttribute, 1, 0);
TranslatesAutoresizingMaskIntoConstraints = false;
BackgroundColor = UIColor.Black;
AddConstraint (heightConstraint);
label = new UILabel {
Text = "You have a new CloudKit notification!",
TextColor = UIColor.White,
TextAlignment = UITextAlignment.Center,
TranslatesAutoresizingMaskIntoConstraints = false,
Hidden = true,
UserInteractionEnabled = true
};
AddSubview (label);
button = new UIButton ();
button.SetTitle ("✕", UIControlState.Normal);
button.AddTarget (Close, UIControlEvent.TouchDown);
button.TranslatesAutoresizingMaskIntoConstraints = false;
button.Hidden = true;
AddSubview (button);
var rightConstraint = NSLayoutConstraint.Create (this, RightMargin, Equal, button, Right, 1, 0);
AddConstraint (rightConstraint);
var centerConstraint = NSLayoutConstraint.Create (this, CenterY, Equal, button, CenterY, 1, 0);
AddConstraint (centerConstraint);
var leftConstraint = NSLayoutConstraint.Create (this, LeftMargin, Equal, label, Left, 1, 0);
AddConstraint (leftConstraint);
var rightLabelConstraint = NSLayoutConstraint.Create (button, Left, Equal, label, Right, 1, 8);
AddConstraint (rightLabelConstraint);
var centerLabelConstraint = NSLayoutConstraint.Create (this, CenterY, Equal, label, CenterY, 1, 0);
AddConstraint (centerLabelConstraint);
var tapGestureRecognizer = new UITapGestureRecognizer (ShowNotification);
label.AddGestureRecognizer (tapGestureRecognizer);
}
示例11: SetupMainButton
private void SetupMainButton ()
{
mainButton = new UIButton (UIButtonType.System);
mainButton.TitleLabel.Font = UIFont.SystemFontOfSize (80);
mainButton.SetTitle (SingleWord, UIControlState.Normal);
mainButton.SizeToFit ();
mainButton.TranslatesAutoresizingMaskIntoConstraints = false;
mainButton.AddTarget (this, new Selector ("PrintWord"), UIControlEvent.TouchUpInside);
View.AddSubview (mainButton);
var mainButtonCenterXSideConstraint = NSLayoutConstraint.Create (mainButton, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterX, 1.0f, 0.0f);
var mainButtonCenterYsConstraint = NSLayoutConstraint.Create (mainButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterY, 1.0f, 0.0f);
View.AddConstraints (new [] {
mainButtonCenterXSideConstraint,
mainButtonCenterYsConstraint
});
}
示例12: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
// Perform custom UI setup here
nextKeyboardButton = new UIButton (UIButtonType.System);
nextKeyboardButton.SetTitle ("Next Keyboard", UIControlState.Normal);
nextKeyboardButton.SizeToFit ();
nextKeyboardButton.TranslatesAutoresizingMaskIntoConstraints = false;
nextKeyboardButton.AddTarget (this, new Selector ("advanceToNextInputMode"), UIControlEvent.TouchUpInside);
View.AddSubview (nextKeyboardButton);
var nextKeyboardButtonLeftSideConstraint = NSLayoutConstraint.Create (nextKeyboardButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1.0f, 0.0f);
var nextKeyboardButtonBottomConstraint = NSLayoutConstraint.Create (nextKeyboardButton, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1.0f, 0.0f);
View.AddConstraints (new [] {
nextKeyboardButtonLeftSideConstraint,
nextKeyboardButtonBottomConstraint
});
}
示例13: PrepareDialogViewController
protected override void PrepareDialogViewController(UIViewController dvc)
{
base.PrepareDialogViewController (dvc);
NavigationBarLabel = InterfaceHelper.LabelForTitle (Caption.ToUpper());
dvc.NavigationItem.TitleView = NavigationBarLabel;
var backButton = new UIButton (new RectangleF (0, 0, 25, 25));
backButton.SetBackgroundImage (UIImage.FromFile ("Images/General/BackButton.png"), UIControlState.Normal);
backButton.SetBackgroundImage (UIImage.FromFile ("Images/General/BackButtonHighlighted.png"), UIControlState.Highlighted);
backButton.AddTarget((object sender, EventArgs args) => GoBack(dvc),
UIControlEvent.TouchUpInside);
BackButton = new UIBarButtonItem (backButton);
dvc.NavigationItem.LeftBarButtonItem = BackButton;
}
示例14: GetCell
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath )
{
// get cell to reuse or create new one.
UITableViewCell cell;
if (rssType == ListViewControllerRSSType.BNRFeed) {
cell = tableView.DequeueReusableCell("UITableViewCellBNR");
if (cell == null) {
cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "UITableViewCellBNR");
}
}
else {
cell = tableView.DequeueReusableCell("UITableViewCellApple");
if (cell == null) {
cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "UITableViewCellApple");
}
}
// Get item and initialize cell with item info
RSSItem item = BNRFeedStore.items[indexPath.Row];
cell.TextLabel.Text = item.title;
cell.TextLabel.TextColor = UIColor.Yellow;
cell.DetailTextLabel.Text = item.subForum;
cell.DetailTextLabel.TextColor = UIColor.Yellow;
cell.UserInteractionEnabled = true;
cell.BackgroundColor = UIColor.Clear;
cell.Accessory = UITableViewCellAccessory.None;
cell.SelectedBackgroundView = new UIView(){
Frame = cell.Frame,
BackgroundColor = UIColor.FromRGB(0.3f, 0.3f, 0.3f)
};
// For BNRFeed list. set up Favbutton, check if favorite, decorate button accordingly, add to cell view
if (rssType == ListViewControllerRSSType.BNRFeed) {
UIButton favButton = new UIButton(UIButtonType.RoundedRect);
favButton.Frame = new CGRect(cell.Frame.Size.Width-17, 0, 17, 44);
favButton.AddTarget(this, new Selector("favButtonPressed:"), UIControlEvent.TouchUpInside);
favButton.SetTitle("F", UIControlState.Normal);
favButton.SetTitleColor(UIColor.White, UIControlState.Normal);
favButton.BackgroundColor = UIColor.FromRGB(0.3f, 0.3f, 0.3f);
favButton.Tag = indexPath.Row;
favButton.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin;
cell.BringSubviewToFront(favButton);
if (item.isFavorite) {
favButton.SetTitleColor(UIColor.Green, UIControlState.Normal);
favButton.BackgroundColor = UIColor.FromRGB(0.4f, 0.4f, 0.4f);
}
cell.AddSubview(favButton);
}
// Set checkmark for read items.
if (item.isRead)
cell.Accessory = UITableViewCellAccessory.Checkmark;
return cell;
}
示例15: SetupNavigationBar
private void SetupNavigationBar()
{
var backButton = new UIButton (new RectangleF (0, 0, 25, 25));
backButton.SetBackgroundImage (UIImage.FromFile (Images.BackButton), UIControlState.Normal);
backButton.SetBackgroundImage (UIImage.FromFile (Images.BackButtonHighlighted), UIControlState.Highlighted);
backButton.AddTarget(HandleBackButtonTapped, UIControlEvent.TouchUpInside);
backNavigationButton = new UIBarButtonItem (backButton);
NavigationItem.LeftBarButtonItem = backNavigationButton;
}