Comments (8)
UIButton
manages its titleLabel
, so you can't move it into another view hierarchy (like setting it as the shimmeringView
). Instead, I'd suggest making a custom title label:
FBShimmeringView *shimmeringView = [[FBShimmeringView alloc] initWithFrame:...];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:...];
shimmeringView.contentView = titleLabel;
[button addSubview:shimmeringView];
That way, your code controls the the title label directly and can shimmer just that part of it. Let me know if that helps!
from shimmer.
my UIButton
is called userStateButton.
I tried this:
FBShimmeringView *shimmeringView = [[FBShimmeringView alloc] initWithFrame:userStateButton.titleLabel.frame];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:userStateButton.titleLabel.frame];
shimmeringView.contentView = titleLabel;
[userStateButton addSubview:shimmeringView];
It didn't change anything. Maybe I misunderstood you?
from shimmer.
I'm suggesting that you don't use the button's title at all — instead, you create your own shimmering title label and add it to the button.
Your code there looks good, but you'll want to configure the titleLabel
you create so it has some text to show and uses the styling you want. Otherwise, you're just adding an empty UILabel
to the button.
from shimmer.
Actually I believe there might be a bug in FBShimmeringLayer. If you go to layoutSublayers of the class FBShimmeringLayer, you will see the following lines of code :
CGRect r = self.bounds;
_contentLayer.anchorPoint = CGPointMake(0.5, 0.5);
_contentLayer.bounds = r;
_contentLayer.position = CGPointMake(CGRectGetMidX(r), CGRectGetMidY(r));
That propagates the bounds of the FBShimmerLayer to the _contentLayer, which makes the label artificially bigger than what it should be,
This is a screenshot with the original code, in which the label layer expands its bounds to match the ones from the FBShimmeringView (incorrectly aligned)
And this is with the mentioned lines of code removed (properly aligned)
The white square is a border of the label and the blue layer is a border of the shimmering view.
from shimmer.
That behavior is as expected: the content layer will fill the entire shimmering layer. If you want to position the content differently, I'd suggest adjusting how you position the shimmeringn layer to take up the same area that you want the content in.
from shimmer.
The problem here is that with UILabel, when you have multiple lines, filling the entire shimmering layer means that the text will always be in the center, and there will be no possible way to align it anymore.
What would recommend to do for this case without having to modify FBShimmeringLayer?
from shimmer.
If you adjust the label size to match the size of the text inside, you can position it vertically wherever is appropriate. The sizeToFit
method might be useful for that.
from shimmer.
That was one of the first things we tried, but it did not seem to work. We will try again to see if there is anything we did wrong. Thanks!
On a side note: you guys are releasing awesome projects in github. Excellent work!
from shimmer.
Related Issues (20)
- Updates please! HOT 1
- shimmer diagonal animation
- updating the pod to Swift4.0 version
- What happened with this repo? HOT 5
- Unable to add Shimmer Framework manually in custom swift Framework
- Carthage support for Shimmer HOT 1
- Is there any user data that is either being collected or Tracked by the Shimmer
- .
- Assigning to 'id<CALayerDelegate> _Nullable' from incompatible type 'FBShimmeringLayer *const __strong'
- Facebook>Chat panel HOT 1
- Missing Android Support HOT 1
- SIGSEGV when deallocating view controller HOT 1
- ShimmerView does NOT work with Constraints HOT 4
- Tag a new release ? HOT 2
- Issues when used with views inside of UIStackView HOT 1
- Shimmer crashes EarlGrey
- Xcode 8.3 warning HOT 3
- Mask angle/tilt HOT 2
- Please update the CocoaPod!
- please show an example of using this in swift 3 or 4. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shimmer.