Resizing the imageView in a UITableView - ios4

I Created a grouped table view, and I noticed that placing an image in the imageView results in an image that is too large. It overlaps the rounded borders of the cell, which is horrible. I tried looking for a way to resize it, but I found many answers that didn't quite satisfy me. How would you do this? Which is the simplest way to go? The solutions I found where strangely complicated.
Thanks!

The other solutions didn't satisfy me. The only good solution I found is this. You can resize the UIImage which is passed to the UIImageView.

The easy way is doing in Interface Builder. Select your UIImegeView and go to the Inspector 1 view, yo can see View/Mode here choose ScaleAspectFit or ScaleToFill.
Else do it by code:
imageView.contentMode = UIViewContentModeScaleAspectFit;
or
imageView.contentMode = UIViewContentModeScaleToFill;

Sorry I made a mistake. First add you image to the tableview cell:
cell.imageView.image = [UIImage imageNamed:#"image.png"];
then set the content mode:
cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
or
cell.imageView.contentMode = UIViewContentModeScaleToFill;

Related

ScrollingView editable in height Xamarin.ios

I have been trying to create a ScrollingView on Xamarin.ios for several days now which shrinks and enlarges when I establish it, showing a larger scrollable part and hiding the empty part if necessary. I'm trying to handle it like this:
ScrollView.ContentSize = new CGSize(View.Bounds.Width, ViewBackground.Bounds.Height - (StackEsercizio.Bounds.Height * 1));
This statement works partially, only when placed in the ViewDidAppear and only for the first time. Do you have any advice or solution?
Finally, I solved it on my own. For the growth of the community, place the solution on github at this link: https://github.com/aleledda98/MyfitnessApp/blob/master/CreaSchedaNew.cs
the scrolling view moves dynamically based on the number of letters entered on a specific UITextField, thanks to all the same <3

Monotouch change existing UIButtonBarItem's image

I would like to use the same UIBarButtonItem but change the Icon to another UIBarButtonSystemItem within the same instance. Is there a way to do this? Also is there a way to detect
which UIBarButtonSystemItem is being used?
var btn = UIBarButtonItem(UIBarButtonSystemItem.Play, null)
btn.?? = UIBarButtonSystemItem.Pause
choper pointed to me to a question that explained that I could not alter the image instance.
I basically followed the advice of that post and I toggle between two buttons(play and pause)

I don't want to change color of JButton when pressed

Color newColor = new Color(197,222,90);
JButton newButton;
newButton = new JButton(icon);
newButton.setBacgroundColor(newColor);
When it is pressed it changes color. How can I keep it from changing color? I have multiple buttons, so if there is solution in one or two rows please help me, and keep in mind that I'm beginner, writing some huge classes won't help me, because I have multiple buttons with different names to be affected with this.
EDIT: Solution in one line is:
UIManager.put("Button.select", newColor);
But it changes all button colors but I need another to have different a color.
EDIT2: After some research I figured out there isn't an easy solution (but it should be). How I see it I have 2 solutions, 1. is to break buttons to separate classes and set UIManager for them, and second is to make custom buttons. It is just too much work for button.
I've found nothing that can change that particular behavior on a normal JButton. The problem being, that whatever you write in your actionlistener for the button, will occur AFTER you've let go of the mousebutton, and not "while clicking".
There are workarounds, however.
My preferred choice is, to remove all graphics from the button, and then add your own images to the button's regular and pressed states. You could take a screenshot of your GUI, cut out the button, and set that image to be both states.
JButton myButton = new JButton();
// Sets button x, y, width, height. Make the size match the image.
myButton.setBounds(5, 30, 100, 30);
// Remove border-graphics.
myButton.setBorder(null);
// Remove default graphics from the button
myButton.setContentAreaFilled(false);
// Remove the focus-indicating dotted square when focused (optional)
myButton.setFocusPainted(false);
// Here, myImage is a simple BufferedImage object.
// You can set one like this, provided you have an "images" package,
// next to your main class (ex: com.somecompany.someprogram.images),
// that contains an image:
BufferedImage myImage = ImageIO.read(getClass().getResource("images/myImage.png"));
// Then we simply apply our image to both states for the button, and we're done.
myButton.setIcon(new ImageIcon(myImage));
myButton.setPressedIcon(new ImageIcon(myImage));
Obviously there are many ways to retain and load an image, but since that's not the issue here, I'll leave additional methods out of it.
There's no need to go through it all countless times, though. It should be pretty easy to write your own custom implementation of the JButton class, in which a custom constructor takes a single parameter, being the BufferedImage, and then the constructor sets it up accordingly (changes the icons). Then all you have to do when you create a new JButton, is to use your own class, and pass it an image:
JButton btn = new MyCustomJButton(myImage);
You could also easily get along with very few images. All you need is a HashMap which holds all the images, with a String as a key. Imagine you need 4 OK-buttons. You make a single image of a button with the text "OK" written on it. Then you put that image into the HashMap, like so:
myMap.put("OK", myImage);
Then you could do this when creating a button, over and over again if you'd like more:
JButton btn = new MyCustomJButton(myMap.get("OK"));
Alternatively:
Another way of achieving this, which is pretty elaborate, but probably considered "the right way", is to use ButtonUI, as presented in this answer to another post.
If the OP is referring to the temporary change of background colour on a button with an icon at the moment the mouse is pressed, the following statement does the trick:
button.setContentAreaFilled(false);
"If you wish to have a transparent button, such as an icon only button, for example, then you should set this to false."
This took me a long time to figure out. It seems to be a little known technique, perhaps since its name gives little clue as to its effect.
With only first lane we can still see that it is clicked. You need to combine those two:
button1.setContentAreaFilled(false);
button1.setEnabled(false);
and if you don't wanna in grey color you put another button under him.
panelname.add(button1,+5,+5); \\(first not clicable, not visible button, notice +5)
panelname.add(button2,-5,-5); \(-5,-5 means it is 5 points under panel)

Dynamic UI ListView

If I have a xml file linear layout with CheckBox, TextView and ImageView and want this to display as scrollable list, having different name and different pictures in every rom of ListView , how can I do it. I am really confused, can you please help me understand. Thank you.
What you're trying to achieve is a custom list row. There are plenty of examples around:
http://appfulcrum.com/?p=311
http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

Limiting Text to spark textarea available size

I'm trying to build a dynamically sized spark textArea which limits the possible text to its size.
E.g the textarea is set to width="300" and height="100". Now the user should only be able to enter or paste as much text as can be visible in the component. I don't want the textArea to scroll or linebreak if more text is entered.
I tried all sorts of approaches, but none with success.
Help is highly appreciated!
I encountered the same issue but no perfect solution is found. But I found a simple workaround for this issue.
Spark TextArea has a textDisplay attribute of type IEditableText. by default, a RichEditableText component is assigned to this attribute. There is a property called contentHeight in this component. I used this property to determine if the text height exceeds textArea height. So my simple solution is like this:
protected function textArea1_changeHandler(event:TextOperationEvent):void {
if (textArea1.textDisplay is RichEditableText){
if ((textArea1.textDisplay as RichEditableText).contentHeight > textArea1.height){
textArea1.maxChars = textArea1.text.length;
}
else {
textArea1.maxChars = 0;
}
}
}
Of cause, this needs to be fine tuned before using in an application. But I wanted to post the solution as soon as possible :) I will post exact logic required. But I think you can do it by your own too...
for a Spark textArea I used this on each change of text:
while (textArea.textFlow.flowComposer.numLines>textArea.heightInLines)
textArea.text = textArea.text.substr(0,textArea.text.length-1);

Resources