Weird thing occurs when using sizetofit of a UITextView in IOS7 - uitextview

When I test my app on IOS7 simulator.
Sometimes I found it is weird when I using sizeToFit of a UITextView.
The frame after sizeToFit seems right but the text can only show partly just like the photo below. (The gray area represents the UITextView new frame after sizeToFit, the whole sentence should be "which sparked a tense relationship between the two.")
The UITextView text is set via attributedText.
It seems the problem occurs with some sentences only and is OK for most sentences.
I met this problem several times and can not solve it yet.
Any help will be appreciated. Thanks.
Update:
Finally I solve the problem in an ugly way. I reset the text of the textView.
NSString *text = textView.text;
textView.text = #"";
textView.text = text;
Now it can show the whole content after sizeToFit.
I think it seems like a IOS 7's bug.

I had the same problem, it took me a while to figure it out, you simply need to resize the text container
[textview sizeToFit];
[textview.textContainer setSize:textview.frame.size];

Noticed in IOS7 sizeToFit wasn't working also - perhaps the solution may help you too, needs the additional layoutIfNeeded
[UITEXTVIEW sizeToFit];
[UITEXTVIEW layoutIfNeeded];
[UITEXTVIEW setTextContainerInset:UIEdgeInsetsMake(0, 0, 0, 0)];

Have you got "clip subviews" checked in interface builder?
Try to uncheck it or setting this property to "NO".

Try this it worked for me.
[textView setTextContainerInset:UIEdgeInsetsMake(0, 0, 0, 0)];

Related

how to see labels without losing middle text in doughnut chart

I am trying to build a doughnut chart with Chart.js and added a text in the middle blank area. Unfortunately, when I drag my mouse over the graph, the text disappears. I found that, if I make the showTooltips: false in the options part, the text would become permanent, but I lose the labels this time.
Q1: Does anyone know how to make text permanent without losing the labels?
Q2: Does ChartNew working fine with Chrome? I heard that there are some problems with the latest chrome and opera versions.
Thank you :)
Q1: Does anyone know how to make text permanent without losing the labels?
Just extend the doughnut chart to (always) draw your middle text after the chart draw is complete. Something like
Chart.types.Doughnut.extend({
name: "DoughnutAlt",
draw: function(){
Chart.types.Doughnut.prototype.draw.apply(this, arguments);
this.chart.ctx.font = Chart.helpers.fontString(14, "normal", "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif");
this.chart.ctx.fillStyle = "Black";
this.chart.ctx.textAlign = "center";
this.chart.ctx.textBaseline = "middle";
this.chart.ctx.fillText("Hello World!", this.chart.width / 2, this.chart.height / 2);
}
});
Fiddle - http://jsfiddle.net/upbcbyfb/
Q2: Does ChartNew working fine with Chrome? I heard that there are
some problems with the latest chrome and opera versions.
A cursory (titles only :-)) glance of the GitHub issue list (https://github.com/nnnick/Chart.js/issues?utf8=%E2%9C%93&q=milestone%3Av2.0+) does not show anything specific to Chrome or Opera.
If there is something specific you want to try out, you can always fiddle your code into the latest (awesomely customizable) version (you have to make a few changes though)
Here is a fiddle to get you started - http://jsfiddle.net/beehe4eg/
That said, the current v2.0.0 (alpha 3) is a pre-release version (see
https://github.com/nnnick/Chart.js/releases), so you probably don't want to switch your production code to this right now.

core-drawer-panel vs paper-fab z-index

I've got a fairly basic core-drawer-panel setup with a core-header-panel inside another core-header-panel in the main panel of core-drawer-panel. With me so far? OK.
Now in that container I have a paper-fab, which is great except it appears on top of the drawer when it slides out. I've tried messing about with z-indexes but can't seem to affect the drawer's z-index at all.
Anyone faced a similar issue?
Thanks!
I had the same issue. Setting z-index of the drawer to big number solved it for me, without any side effects
core-header-panel[drawer] {
z-index: 9999;
}

How to save images drawn with drawRect BEFORE VC.m tries to load them?

Thanks for all the help this site has been to help answer many questions!
I overrode drawRect in subclass of UIView, drew a bunch of images and save them as PNGs.
Next I am trying to load the images for use in ViewController.m
Finally got animations working, but experienced a time when VC would try to load the images before Draw2D had saved them. Found that NSLog worked well to see sequence of events:
if ([self loadNamedImage:nameToLoad]) {
[image2set addObject:[self loadNamedImage:nameToLoad]];
NSLog(#"Loaded %#", nameToLoad8); }
loadNamedImage is the method that returns the loaded images. Adding if/exist seemed to fix the problem for awhile, but I want to properly use something like
performSelectorOnMainThread:withObject:waitUntilDone:;
// where to place command, which object, etc?
tried using sleep statement in VC hoping the sleep time would be used to save the images before trying to load them .. how can the program startup sequence be adjusted enough to make this work?
dBC
found that using viewDidAppear vs viewDidLoad solved my problem for awhile.
Recently started working with Gestures and reset simulator setting as suggested to fix finding needed files. Now the images won't load again because viewDidAppear tries to load pics before overridden DrawRect method draws them. Tried different restore points, clean project, and uninstall app from simulator to no avail :o(
Examples of where and how to implement addDependency, GCD or other solution are greatly appreciated!

Android NDK glReadPixels() from offscreen buffer

I'm writing a game using android ndk. I'm using picking to select objects in opengl.
For that i have an offscreen framebuffer object where i render into and i use glReadPixels() to get the color from the FBO. The color then encodes the id of the clicked object.
The problem is glReadPixels() does not work. It just does not read any color values.
Is there anything I have to do, to make it work?
GLubyte pixel[4] = {0,0,0,0};
glReadPixels(x, y , 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void *)pixel);
This is how i try to use readpixels. But the result is always (0,0,0,0).
I checked the coordinates (x,y). They are fine. The combination GL_RGBA, GL_UNSIGNED_BYTE should also be supported by any opengl es 2.0 implementation, according to the opengl docs.
I've read something about permissions that I have to set in the android manifest.
I tried to add a permission like this:
<uses-permission android:name="android.permission.READ_FRAME_BUFFER"/>
but it didn't work either.
Has anyone an idea what the solution might be? or where I can look at?
the problem was just a threading issue. all openGL calls have to be done in the same thread. Otherwise this can result in weird behavoir like this and worse.
Dirk's suggestion fixed my issue. It was thread context.

How to display high resolution images in iOS4 using UIImageView

I wanted to know how should I use high res images in iOS4 sdk using UIImaageView.
blackBox = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"alert_bg.png"]];
blackBox.frame = CGRectMake(98.0f, 310.0f, 573.0f, 177.0f);
When I use this code I get strange results... the image does not get the correct size. It is looking very big on iPhone 4 screen.
Should I use 326 ppi images?
I have read http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/SupportingResolutionIndependence/SupportingResolutionIndependence.html this but I am very confuse.
Thanks
Saurabh
The key thing to understand about supporting the Retina Display is that, in your code, the screen is always 320x480. You don't need to double the resolution of anything but your image resources themselves. In this case, you just need to put two resources in your app bundle: an alert_bg.png that fits on a 320x480 screen—in this case, I'd guess that'd be 286x88—and an alert_bg#2x.png, exactly double the size of the other, that fits on a 640x960 one. If you ask UIKit for [UIImage imageNamed:#"alert_bg"], it'll automatically pick the correct-resolution resource for the current screen.
You should provide a 480x320 pixels image for the 3G, 3GS and original iPhone, named "alert_bg.png" and another 960x640 px one, named "alert_bg#2x.png" for the iPhone 4.
The "#2x" in the name is automatically added by iOS and loads the image automatically if it finds it, instead of the standard resolution one.

Resources