I have a simple alert shown below that is displayed differently in Windows and Linux. There are quite a bit of posts to scale button size depending on text but I essentially want the opposite. The Buttons should stay the same size and the text should scale to fit (like it appears to be doing in windows)
protected static void setDifficulty(){
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Welcome to the game of Memory");
alert.setHeaderText("How difficult should your oppenent be?");
alert.setContentText("Please choose your desired difficulty.");
ButtonType button1 = new ButtonType("Nice n' Easy");
ButtonType button2 = new ButtonType("So So");
ButtonType button3 = new ButtonType("Super Freak");
ButtonType buttonCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
alert.getButtonTypes().setAll(button1, button2, button3, buttonCancel);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == button1){
MemoryField.difficulty = 10;
} else if (result.get() == button2) {
MemoryField.difficulty = 5;
} else if (result.get() == button3) {
MemoryField.difficulty = 0;
} else {
Platform.exit();
}
}
On Windows:
On Ubuntu:
The only way I was able to avoid this problem on Linux was to get a handle to the button, and set the preferred width:
for(ButtonType buttonType : alert.getButtonTypes()){
Button button = (Button) alert.getDialogPane().lookupButton(buttonType);
button.setPrefWidth(100);
}
Related
I have created a view like this in my xamarin iOS mobile project.
User will be able to click on the capture images button to take a picture and set the image property of the image view. I would like to know how can i allow the user longpress a image (after it has been captured) and popup a message box to delete the image.
I have tried what Sameer has suggested in his comment like so in my ViewDidLoad
var gestureRecognizer = new UILongPressGestureRecognizer();
gestureRecognizer.AddTarget(() => ButtonLongPressed(gestureRecognizer));
img1.AddGestureRecognizer(gestureRecognizer);
img2.AddGestureRecognizer(gestureRecognizer);
When i click and hold on the image nothing happens. I have added these image views via the designer.
After a little more research and using the comment from #Junior Jiang - MSFT. I have made a bit progress but i would like to know which UIImage view has been clicked.
Heres my current code:
public JobImagesViewController(Job passedInCurrentJob) : base("JobImagesViewController", null)
{
currentJob = passedInCurrentJob;
uIImageViews = new List<UIImageView>();
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
uIImageViews.Add(img1);
uIImageViews.Add(img2);
uIImageViews.Add(img3);
uIImageViews.Add(img4);
uIImageViews.Add(img5);
uIImageViews.Add(img6);
uIImageViews.Add(img7);
uIImageViews.Add(img8);
uIImageViews.Add(img9);
uIImageViews.Add(img10);
InitialiseImageGrid();
// Add a Save button to the navigation bar
this.NavigationItem.SetRightBarButtonItem(
new UIBarButtonItem("Save", UIBarButtonItemStyle.Done, (sender, args) =>
{
//TODO if else block with all logic to check if there are images etc.
//TODO prompt user and ask if they would like to save images.
UIAlertView alert = new UIAlertView("Save Images?", "Save images against the Job?", null, "Yes", new string[] { "No" });
alert.Clicked += (s, e) =>
{
if (e.ButtonIndex == 0) // Yes clicked
{
SaveJobImages();
}
};
alert.Show();
}), true);
}
[Export("ImageLongPressed:")]
public void ImageLongPressed(UILongPressGestureRecognizer gestureRecognizer)
{
if (gestureRecognizer.State != UIGestureRecognizerState.Began)
{
return;
// Needed because selector is executed twice, because Long-press gestures are continuous
}
// Perform action of opening the dialog to select/take a picture, replacing the ? image with the new image
UIAlertView alert = new UIAlertView("Delete this image ?" , "Are you sure you want to delete this image?", null, "Yes", new string[] { "No" });
alert.Clicked += (s, e) =>
{
if (e.ButtonIndex == 0) // 'Accept' clicked
{
// TODO how to get the image which has been clicked??
}
};
alert.Show();
}
private void InitialiseImageGrid()
{
_imageList = DataAccess.GetImages(currentJob.jobAddressID);
var imageBytes = _imageList.Select(x => x.ImageBytes).ToList();
var gestureRecognizer = new UILongPressGestureRecognizer(this, new ObjCRuntime.Selector("ImageLongPressed:"));
gestureRecognizer.AddTarget(() => ImageLongPressed(gestureRecognizer));
// Populate the image views.
// TODO need to find a way to assign it to every imageview on the view without looping maybe linq???
int i = 0;
foreach (var item in imageBytes)
{
var imagedata = NSData.FromArray(item);
var img = UIImage.LoadFromData(imagedata);
if (uIImageViews != null && uIImageViews.Count > i)
{
uIImageViews[i].UserInteractionEnabled = true;
uIImageViews[i].AddGestureRecognizer(gestureRecognizer);
uIImageViews[i].AddGestureRecognizer(gestureRecognizer);
uIImageViews[i].Image = img;
}
i++;
}
It depends on how you are creating your view, are you using a XIB with all the images on there as buttons with images, and IBActions connected to those buttons. just make the sender a UILongPressGestureRecognizer.
If you are doing it through code, then in your ViewDidLoad you want to set your buttons to have an initial ? (or Image Needed) background image and then you add the UILongPress GestureRecognizer to each on of them. So if you had one button, you would do this:
public override void ViewDidLoad ()
{
// Perform any additional setup after loading the view
UIButton button = new UIButton (new System.Drawing.RectangleF(100, 100, 100, 30));
button.SetBackgroundImage ("imageNeeded", UIControlState.Normal);
var gestureRecognizer = new UILongPressGestureRecognizer ();
gestureRecognizer.AddTarget(() => this.ButtonLongPressed(gestureRecognizer));
button.AddGestureRecognizer(gestureRecognizer);
this.View.Add (button);
}
public void ButtonLongPressed(UILongPressGestureRecognizer gestureRecognizer)
{
if (gestureRecognizer.State != UIGestureRecognizerState.Began)
{
return;
// Needed because selector is executed twice, because Long-press gestures are continuous
}
// Perform action of opening the dialog to select/take a picture, replacing the ? image with the new image
}
If want to use UILongPressGestureRecognizer in UIImage, should set ImageView's UserInteractionEnabled be true.
As follow:
List<UIImageView> imageViews = new List<UIImageView>();
UIImage image = UIImage.FromFile("off.png");
ImageViewOne.Image = image;
ImageViewOne.Tag = 1;
ImageViewTwo.Image = image;
ImageViewTwo.Tag = 2;
imageViews.Add(ImageViewOne);
imageViews.Add(ImageViewTwo);
foreach (var imageview in imageViews)
{
imageview.UserInteractionEnabled = true;
UILongPressGestureRecognizer uITapGestureRecognizer = new UILongPressGestureRecognizer();
uITapGestureRecognizer.AddTarget(() => { Console.WriteLine("You choose View " + imageview.Tag); });
imageview.AddGestureRecognizer(uITapGestureRecognizer);
}
Here is official document from Apple.
I use PDFKit in iOS as PDF renderer and I have problem with background color in radio button.
I iterate all PDF annotations on all pages in the document.
override func viewDidAppear(_ animated: Bool) {
//let pdfData = ... received data from file storage ...
if let document = PDFDocument(data: pdfData) {
for i in 0...document.pageCount {
if let page = document.page(at: i) {
for annot in page.annotations {
if annot.widgetControlType == .radioButtonControl {
annot.backgroundColor = UIColor.red
}
}
}
}
}
}
When I set the background color, nothing happens.
But when I try to set the background color to the type of Text annotation, the color changes.
The difference between the Radio button and the Text annotation is in its type.
The Radio button has a widgetFieldType == .button and the Text has a widgetFieldType == .text.
I think this is the reason why it doesn't work.
Next I try to remove annotation, change his background color and add again. This also doesn't work.
if annot.widgetControlType == .radioButtonControl {
page.removeAnnotation(annot)
annot.backgroundColor = UIColor.red
page.addAnnotation(annot)
}
But when I create a new instance of PDFAnnotaion, and I add it to the page, it works.
if annot.widgetControlType == .radioButtonControl {
page.removeAnnotation(annot)
let newAnnot = PDFAnnotation(bounds: annot.bounds, forType: .widget, withProperties: nil)
newAnnot.backgroundColor = UIColor.red
newAnnot.widgetStringValue = annot.widgetStringValue
page.addAnnotation(newAnnot)
}
The big problem is that the value of this Radio button is not displayed, even though it contains the value itself.
If in another method I get all the values from PDF annotations, there is also the right value from this radio button.
The Radio button contains the value, only it is displayed.
I tried to copy all the properties PDF annotation from the annot to newAnnot, but it didn't help.
How to properly change the background color of the Radio button and display its value?
I am developing an app as like rich editor text and as i have wrote the text on editable web view but keyboard hides the lines. I am also using some javascript coding but not succeeded.
this.updateOffset = function() {
try{
var sel = window.getSelection();
range = sel.getRangeAt(0);
if(this.tmpSpan==null){
this.tmpSpan = document.createElement('span');
}
range.insertNode(this.tmpSpan);
this.yOffset = this.tmpSpan.offsetTop;
this.xOffset = this.tmpSpan.offsetLeft;
this.tmpSpan.parentNode.removeChild(this.tmpSpan);
}
catch(exc){
log('updateOffset:' + exc.toString());
}
}
// eContent is the div with 'contenteditable', while visibleHeight is an int, set from objective-c (depending on where the webview is positioned, keyboard height and screen height)
this.scrollToVisible = function(){
try {
if(this.eContent.clientHeight>this.visibleHeight){
this.updateOffset();
if(this.yOffset<window.pageYOffset){
window.scrollTo(0, this.yOffset);
}
else if(this.yOffset-window.pageYOffset>this.visibleHeight){
window.scrollTo(0, this.yOffset-this.visibleHeight);
}
}
}
catch (exc){
log('scrollToVisible: ', exc.toString());
}
}
Please suggest what we should do.
Keyboard is not appearing for the text field on the simulator.
Created The textfield.
txt_UserName = new UITextField {
Placeholder = "Enter Username",
BorderStyle = UITextBorderStyle.RoundedRect,
Font = UIFont.FromName(Constants.KHELVETIC,Constants.KFontSize12),
VerticalAlignment = UIControlContentVerticalAlignment.Center,
AutocorrectionType = UITextAutocorrectionType.No,
AutocapitalizationType = UITextAutocapitalizationType.None,
ClearButtonMode = UITextFieldViewMode.WhileEditing,
LeftViewMode = UITextFieldViewMode.Always,
ReturnKeyType = UIReturnKeyType.Next,
BackgroundColor = UIColor.White,
ShouldReturn = delegate {
txt_Email.BecomeFirstResponder ();
return true;
}
};
txt_Email = new UITextField {
Placeholder = "Enter Email",
BorderStyle = UITextBorderStyle.RoundedRect,
Font = UIFont.FromName(Constants.KHELVETIC,Constants.KFontSize12),
VerticalAlignment = UIControlContentVerticalAlignment.Center,
AutocorrectionType = UITextAutocorrectionType.No,
AutocapitalizationType = UITextAutocapitalizationType.None,
ClearButtonMode = UITextFieldViewMode.WhileEditing,
KeyboardType = UIKeyboardType.EmailAddress,
LeftViewMode = UITextFieldViewMode.Always,
ReturnKeyType = UIReturnKeyType.Next,
BackgroundColor = UIColor.White,
ShouldReturn = delegate {
txt_Password.BecomeFirstResponder ();
return true;
}
};
Can't find keyplane that supports type 5 for keyboard iPhone-Portrait-PhonePad; using 2870935746_Portrait_iPhone-Complex-Pad_Default
Its show the above message when I select the Textfield.
You need to uncheck the hardware keyboard option so that the keyboard on the emulator pops up .
because if you have the hardware keyboard option on you will need to connect a keyboard to you device to check it it is taking that.
I have an issue where I need to create some buttons depending on some boolean values.
If button1 = true I should create button1, if button2 = true I should create button2 and if button3 = true I should create button3.
So there can be 8 combinations:
1 - button1, button2, button3 (button1 = true, button2 = true, button3 = true)
2 - button1, button2 (button1 = true, button2 = true, button3 = false)
3 - button1, button3
4 - button2, button3
5 - button2, button1
6 - button1
7 - button2
8 - button3
My issue is how to find the correct combination out of the 8.
If button1 = true I should create button1, if button2 = true I should create button2 and if > button3 = true I should create button3.
you seem to have written the complete pseudocode already. try three if statements.
Not sure what the question really is: seems like programming 101 (or programming for dummies page 2). The obvious approach:
if (button1) { createButton1(); }
if (button2) { createButton2(); }
if (button3) { createButton3(); }
If the combinations are a bit more complex, you might need separate statements:
if (button1 && button2 && button3) {
// create required buttons for case 1
} else if (button1 && button2) {
// create required buttons for case 2
}
...
The order of the cases in the questions are ok - you need most specific to least specific (if "just button1" was first, it would "steal" all the other cases relying on button 1.)
Another approach is to encode the booleans into an int and use a switch. This is probably a bit more extensible if you might need to add complex conditions for buttons 4 5 and 6
int choice = button1 ? 1 : 0;
choice += button2 ? 2 : 0;
choice += button3 ? 4 : 0;
switch(choice) {
case 0: break; // no buttons
case 1: // just button1
case 2: // just button2
case 3: // button1 and button2
...
}