Large width of UILabel Cause memory issue - iphone

I want some marquee label type control in my application. I have created it but the problem is as below:
1.I have setup the scrollview first and then in that scrollview i have added UILabel with large text around 7000 character.and i am shifting content offset of the UIScrollView to make a text scrolling.
Now when allocating label, i make the width of the label according to the stringsize width like below:
UIFont *font = autoScrollLabel.font;
CGSize stringSize = [str1 sizeWithFont:font];
float width = stringSize.width;
and i give this width (its around 250000) to the UILabel width Like below:
autoScrollLabel.frame = CGRectMake(15,25,width,98);
=====
Now the problem is if i am allocating this width to UILabel with then it occupy around 300MB size of the application and at some instant it crashed the application due to memory issue.
Can anyone had ever faced this issue then please help on how to solve this memory issue or anyone who have any idea please put you suggestion.
I have also other functionality like play, pause, scroll text with animation, and move the text offset according to the UISlider and start it from there.
Thanks

A UILabel will render all the text at once event if it is off the screen. This is what is causing your memory issue.
As an alternative, could you use a UITextView in your code to achieve the same functionality?
UITextView inherits from UIScrollView so you can set the textview's frame to bounds of the superview but adjust the contentSize property to stringSize
Edit: Sorry, the above wouldn't work as you cannot control the way the UITextView renders its text.
How about trying this: https://github.com/cbpowell/MarqueeLabel

Related

Marquee and static UILabel text

In my application i have two options to display text in UILabel .First is to use marquee like effect , so that long text can scroll along its width. I am using size of 350 for marquee. Other option is called static. In this however long is the text it should not marquee and show whole text in UILabel. UIlabel should adjust its font and size so as to fit in the frame of uiview i.e width = 480 and height = 320 in landscape mode. I have completed with the marquee animation but i am not able to figure out how to display static tex in uilabel so that it will changes its size and font according to the length of text.
AS alternative you can create same thing with UIView and Timer. Please refer below URL
https://github.com/jeffhodnett/JHTickerView
https://github.com/MugunthKumar/MKTickerViewDemo
https://github.com/caydenliew/CLTickerView
HTML marquee not working in iOS 5.1

CGAffineTransformMakeScale on UITextView

I have an instance of UITextView. It is actually a box, and when user taps on it, I want to make it bigger. So I implemented CGAffineTransformMakeScale in tap event.
The problem is, the text inside the UITextView gets fuzzy and blurry. I set contentMode = UIViewContentModeRedraw, but didn't affect it.
Any idea? Many thanks in advance.
This is always going to happen. If you scale it like that using the transform it will always get blurry because the whole textview is scaled, including all contents.
The only way to prevent this is not using the transform scale but simply make the textview frame bigger!
Can you try to reset the text after making the font bigger on the tap?
say
NSString *placeholderText = textView.text;
textView.font = // bigger font proportional to scaling
textView.text = placeholderText;

UILabel text scaling, Programmatically?

I want to change my UILabel text or UILabel itself's size by using UISlider, I know it's something we don't do it for an normal application. But basically I am trying new and different things to explore Objective -C language and iOS platform.
So far I am able to change colour of a font by UISlider, Which looks really great, So thought of changing it's size too by UISlider. Below I am posting pictures to clarify my thoughts visually!
From ----->
To ------->
While making those images I realised I might have to change size of UILable and Size of font too. Am I right? Is this possible?
textLabel.font = [UIFont boldSystemFontOfSize:slider.value];
CGSize newSize = [textLabel.text sizeWithFont:textLabel.font];
This should make it
an alternative is to set the fram of the label above the complete size above the textField and set textAlignement = center
its quite simple actually
According to slider change value dynamically increase height and width of your label..
There can be many ways you can handle this, one way would be to just change the font size with slider and when you change the font calculate the frame size with sizeWithFont: instance method of NSString.

iOS - UITextView doesn't draw text?

I have a UITextView on the screen.
This UITextView is covered by a UIView.
When I set the text for this UITextView, if the textView is not visible (UIView is covering it), it doesn't draw the text.
So when I remove the view that is covering my textView there is no text in my textView. If I try scrolling the textview the text will appear suddenly.
any way to force the UITextView to draw the text at all times? (This only happens when I have too much text in it (about 1000 characters))
I tried calling [textView setNeedsDisplay], before and after setting 'text' and it didn't fix the problem
I have the same problem, my UITextView does not draw text until I try scrolling it or its parent. [textView setNeedsDisplay] does not work for me. Finally, I increase textView 1px and the problem's gone.
CGRect frame = textView.frame;
frame.size.height += 1;
textView.frame = frame;
I know this method is ugly but it does work.
Most things in the system will not display when hidden, which would be a waste of resources.
The correct approach is to call setNeedsDisplay: on the UITextView AFTER it has been un-hidden, then it should draw immediatley.
The limit to the number of characters in a UITextView seems to be around relatively low (see the post here).
The poster in the link I posted suggests putting your content into a UIWebView, which can handle a large amount of text.
Same problem. We have a textview that is configured and put into the view while hidden or offscreen. Most likely due to Apple optimizing UITextView so that it doesn't do layout and drawing unless it is onscreen and visible.
Calling setNeedsDisplay doesn't work because of the optimizations. setNeedsDisplay gets called quite often, so imagine a UITextView doing layout and drawing quite often? Thus the solution above is ugly but works: add a pixel to the frame which will trigger the UITextView to re-layout and redraw. We went with this solution.
Since UITextView is a subclass of UIScrollView, I did something like this:
CGPoint offset = self.textView.contentOffset;
offset.y++;
[self.textView setContentOffset:offset];
offset.y--;
[self.textView setContentOffset:offset];
the same as #Tùng Đỗ without changing the frame... still looks ugly.

at run-time(objective-c), how do you place a UIPickerView in a resized UIView?

I am seeing that the way to shrink the width of the UIPickerView is to put it in a resized UIView. But the examples are at design time. At run-time(objective-c), how do you place a UIPickerView in a resized UIView, as I am doing this to 4 of them to be side by side ?
thanks
you can use picker.transform = CGAffineTransformMakeScale(0.7, 0.6); something like this and try...
This will reduce the width as well height ...
Try changing the values in the above scale and try it..
and also check this