Image Stretching Only some Part - ios

I want to image stretching some portion of image. Just below cutout off image. But when text increase it stretch full image. But i want to stretch a image after so.link
balloonView.image =[[UIImage imageNamed:#"chatbg.png"] stretchableImageWithLeftCapWidth:50 topCapHeight:0];;
Please check http://postimg.org/image/7d7lzu9n1/f99d1ebd/

General Discussion : In order to create a stretchable UIImage in iOS like 9Patches in android, you can use this:
UIImage * backgroundImg = [UIImage imageNamed:#"bg.png"];
backgroundImg = [backgroundImg resizableImageWithCapInsets:UIEdgeInsetsMake(2,2, 2, 2)];
[imgView setImage:cellBackgroundImg];
you could also use:
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth
topCapHeight:(NSInteger)topCapHeight
basically the image is not stretched in the area leftCapWidth pixels from the left and right edge and topCapHeight pixels from the top and the bottom. When the image is scaled the area inside of these limits is subject to stretching.
OP's issue : I think why you are not able to make it work is because your topCapHeight is set to 0. try something like this :
[[UIImage imageNamed:#"chatbg.png"] stretchableImageWithLeftCapWidth:50
topCapHeight:50];

A stretchable image is divided into 9 parts, if both leftCapWidth and topCapHeight are nonzero.
leftCapWidth
<----->
+--------------+ ^
| | | | |
| A | | B | | topCapHeight
|-----+·+------| v
|-----+·+------|
| C | | D |
| | | |
+--------------+
The central parts are always 1 px in size, and this is the part that is stretched, for example:
leftCapWidth (constant!)
<----->
+------------------+ ^
| | | | |
| A | | B | | topCapHeight (constant!)
v |-----+ - - +------| v
| | . . |
| | . . |
^ |-----+ - - +------|
| C | | D |
| | | |
+------------------+
>-----<
stretched region
Just use this code. If you have still any issue for left side arrow, then change the value of LeftCapWidth like 5,10,20 and then check it.
balloonView.image =[[UIImage imageNamed:#"chatbg.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:20];
Hope, this is what you're looking for. Any concern get back to me.

Related

Keep vertical UIStackView at the minimum width when the alignment is center

If I create a UIStackView with vertical axis and center alignment, how do I keep its width at the minimum possible value, meaning the widest subview?
I can't create a constraint between it and one of the subviews because I don't know which one will be the widest.
This usually happens when I create a leading greater than or equal constraint to the view controller's view with constant 10, and a center horizontally constraint.
In this case, the stack view will have the width equal to the view controller's width - 20, while the subviews will retain their width (e.g. from their intrinsic content sizes if they're labels).
Here is an example:
A--------------+
| B----------+ |
| | C--+ | |
| | +--+ | |
| | D------+ | |
| | | | | |
| | +------+ | |
| +----------+ |
+--------------+
where A is the view controller's view, B is the stack view and C and D are two labels.
So it leaves a gap between the left margins of B and D.
I would instead expect it to look like this:
A--------------+
| B------+ |
| | C--+ | |
| | +--+ | |
| D------+ |
| | | |
| +------+ |
| +------+ |
+--------------+
where the B's width is equal to D's width, because the leading constraint is greater than or equal, and not strictly equal.

Point in rotated rectangle - absolute position

I have a picture in which I'm looking for a rectangle (dotted in the picture below). This rectangle might, however, be rotated. Once I found that rectangle, I extract and, if necessary, rotate it so that it is properly aligned. I then try to locate a given point within that rotated rectangle (the X in the picture below, let's say it is at position (100/20)).
How do I now calculate the position of that point in terms of the original picture (e.g. (120/25))?
|----------------------------------------------------------|
| `......` - |
| `......` .` |
| `......` X - |
| `....```` .. |
| `....```` - |
| -`` `. |
| .. - |
| - `- |
| `. -` |
| - - |
| `- -` |
| - - |
| `- -` |
| -` ````...``` |
| - ````....``` |
| .` ````....``` |
| - ````....` |
| .. ```....` |
| ..` |
| |
| |
| |
|----------------------------------------------------------|

Flexible layout using interface builder

I want to achieve this layout that will resize width in landscape mode and will keep all spaces(gaps) as defined. So single column of UITextView in one row there are two which should take half of the width left when left right and in between gaps are deducted.
+---------------------------------------------+
| <y> |
| +-----------------------------------+ |
| | | |
| +-----------------------------------+ |
| +-----------------------------------+ |
| | | |
| +-----------------------------------+ |
| +----------------+ +----------------+ |
|<x> | 50% | | 50% | <x>|
| +----------------+ +----------------+ |
| +-----------------------------------+ |
| | | |
| +-----------------------------------+ |
| |
+---------------------------------------------+
I tried for a long time checking different constrains like width <= 280 and width >= 280 - both with the same results.
Can someone write step by step what to do to have this layout? Does it matter that it is inside the UIScrollView?
The structure is:
View
Scroll View
Content View
Round Style Text Field
Round Style Text Field
View
Round Style Text Field
Round Style Text Field
Round Style Text Field
Add an other view around what you want to center.
+-----------------------------------------------+
| <y> |
| +-------------------------------------+ |
| |+-----------------------------------+| |
| || || |
| |+-----------------------------------+| |
| |+-----------------------------------+| |
| || || |
| |+-----------------------------------+| |
| |+----------------+ +----------------+| |
|<x> || 50% | | 50% || <x>|
| |+----------------+ +----------------+| |
| |+-----------------------------------+| |
| || || |
| |+-----------------------------------+| |
| +-------------------------------------+ |
| |
+-----------------------------------------------+
It's easy to center a view within another view.
View
Scroll View
Content View
View
Round Style Text Field
Round Style Text Field
View
Round Style Text Field
Round Style Text Field
Round Style Text Field

Auto layout: auto update constraints when some view is empty

I have a view like this
_______________________________
| | |
| Label 0 |
| ^ |
| Label 1 |
| ^ |
| Label 2 |
| ^ |
| Label N |
|_______________________________|
^ stands for a constraint that links the top of Label X+1 with the bottom of Label X. Label 0 is constrained to the superview's top with a fixed constant.
What I'm trying to achieve is: if some Label X is empty, then Label X+1 has to take its place.
_______________________________
| | |
| Label 0 (empty) |
| ^ |
| Label 1 |
| ^ |
| Label 2 |
| ^ |
| Label N |
|_______________________________|
|
| The new layout
\ /
_______________________________
| | |
| Label 1 | (here it is also Label 0 but is empty)
| ^ |
| Label 2 |
| ^ |
| Label N |
|_______________________________|
Is this possible with auto layout or do I have to programatically check emptiness to update the constraints manually?
Disclaimer: If this questions sounds very basic excuse me, please, I'm migrating from springs and struts and it is a quite criptic for now.
Does it need to change when content is visible? If not try this: you could do an update in the viewWillAppear method. For each label, call
[firstLabel setNumberOfLines:0];
[firstLabel setText:newProductTitleText];
[firstLabel sizeToFit];
Setting number of lines to 0 lets the label dynamically use an many lines as it needs. If this is an empty label that should actually become 0 lines. This will update the frames and autolayout should take care of the rest.

Lining up multiple short nodes in parallel with a single tall node in GraphViz

I want to generate something like this - the alignment of the nodes is the important thing, not the angle of the edges:
+--------------+
| |
+--------------+
| |
V V
+-----+ +-----+ <--- alignment at top
| | | |
| |->| |
| | | |
+-----+ | |
| | |
V | |
+-----+ | |
| | | |
| |->| |
| | | |
+-----+ +-----+ <--- alignment at bottom
| |
V V
+--------------+
| |
+--------------+
The best I've been able to come up with is to stick the two left nodes into a cluster subgraph with a white (=> invisible) border, and set the weight of one of the edges to 0. But it's still not quite right:
digraph G {
// scale things down for example
size="5,5"
rankdir=TD
ranksep=1
nodesep=1
node [shape=box]
node [width=5 height=2]
top
subgraph cluster_left
{
color=white
node [width=2 height=2]
left1
left2
}
node [width=2 height=5]
right
node [width=5 height=2]
bottom
top->left1
top->right
left1->left2
left1->right
left2->right [weight=0]
left2->bottom
right->bottom
}
This comes out like this - poorly aligned:
Any ideas on how to get what I want?
I did it with neato and this script :
digraph G {
layout="neato"
// scale things down for example
size="5,5"
rankdir=TD
ranksep=1
nodesep=1
node [shape=box]
top[pos="5,10!", width=5, height=2]
left1[pos="3.5,7!", width=2, height=2]
left2[pos="3.5,4!", width=2, height=2]
right[pos="6.5,5.5!", width=2, height=5]
bottom[pos="5,1!", width=5, height=2]
top->left1
top->right
left1->left2
left1->right
left2->right
left2->bottom
right->bottom
}
Here is the result :

Resources